/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { // show only active users // TODO: this currently produces duplicates... if ($request->has('active')) { $user1 = Role::find(4)->users()->get(); $users = Role::find(5)->users()->get(); foreach ($user1 as $value) { $users->prepend($value); } $heading = 'Show Active Users'; return view($this->view_all, ['users' => $users, 'heading' => $heading, 'roles' => Role::get(), 'instruments' => Instrument::get()]); } // get all users in the requested order (default by id) $users = User::orderBy(isset($request->orderby) ? $request->orderby : 'id', isset($request->order) ? $request->order : 'asc'); $heading = 'User Management'; // check if user selected a filter if ($request->has('filterby') && $request->has('filtervalue') && $request->filtervalue != 'all') { if ($request->filterby == 'role') { // get all -- USERS -- with this specific role id $role = Role::find($request->filtervalue); $users = $role->users(); $heading = 'User Management - Show ' . ucfirst($role->name) . 's'; } else { if ($request->filterby == 'instrument') { // get all -- USERS -- with this specific instrument id $instrument = Instrument::find($request->filtervalue); $users = $instrument->users(); $heading = 'User Management - Show users playing ' . ucfirst($instrument->name); } else { $users = $users->where($request->filterby, $request->filtervalue); } } } return view($this->view_all, ['users' => $users->get(), 'heading' => $heading, 'roles' => Role::get(), 'instruments' => Instrument::get()]); }
/** * Remove the specified instruments from storage (global UI implementation). * * @param int $id * @return Response */ public function delete($id) { //Delete the instrument $instrument = Instrument::find($id); $instrument->testTypes()->detach(); $instrument->delete(); // redirect return redirect()->to('instrument.index')->with('message', trans('messages.success-deleting-instrument')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // // find a single resource by ID $output = Instrument::find($id); if ($output) { $output->delete(); $message = 'Instrument with id "' . $id . '" deleted.'; return \Redirect::route($this->view_idx)->with(['status' => $message]); } // $message = 'Error! Instrument with ID "' . $id . '" not found'; return \Redirect::route($this->view_idx)->with(['status' => $message]); }