middleware('auth'); $this->middleware('atleast:manage'); $this->middleware('permission:READ_USERS')->only('index', 'show'); $this->middleware('permission:CREATE_USERS')->only('create', 'store'); $this->middleware('permission:UPDATE_USERS')->only('edit', 'update'); $this->middleware('permission:DELETE_USERS')->only('destroy'); } public function index() { return view('manage.users.index', ['title' => "Manage Users", 'users' => \App\Models\User::all()]); } public function create() { return view('manage.users.create'); } public function store() { $user = new \App\Models\User(); $user->name = request('name'); $user->email = request('email'); $user->password = request('password'); $user->role = request('role'); $user->save(); // user assignments (user_assignments.user_id, user_assignments.cinema_id) $cinemas = request('cinemas'); if ($cinemas) { foreach ($cinemas as $cinema) { $user->cinemas()->attach($cinema); } } return redirect()->route('manage.users'); } public function show($id) { return view('manage.users.user', ['user' => \App\Models\User::findOrfail($id)]); } public function update($id) { $user = \App\Models\User::findOrfail($id); $user->name = request('name'); $user->email = request('email'); $user->password = request('password'); $user->role = request('role'); $user->save(); // user assignments (user_assignments.user_id, user_assignments.cinema_id) $cinemas = request('cinemas'); if ($cinemas) { foreach ($cinemas as $cinema) { $user->cinemas()->attach($cinema); } } return redirect()->route('manage.users'); } public function destroy($id) { $user = \App\Models\User::findOrfail($id); $user->delete(); return redirect()->route('manage.users'); } }