diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php new file mode 100644 index 00000000..78d55f97 --- /dev/null +++ b/app/Http/Controllers/Admin/UserController.php @@ -0,0 +1,184 @@ +userRepo = $userRepo; + } + + /** + * Display a listing of the User. + * + * @param Request $request + * @return Response + */ + public function index(Request $request) + { + $this->userRepo->pushCriteria(new RequestCriteria($request)); + $Users = $this->userRepo->all(); + + return view('admin.users.index', [ + 'users' => $Users, + ]); + } + + /** + * Show the form for creating a new User. + * + * @return Response + */ + public function create() + { + return view('admin.user.create', [ + 'airlines' => Airline::all()->pluck('name', 'id'), + ]); + } + + /** + * Store a newly created User in storage. + * + * @param CreateUserRequest $request + * + * @return Response + */ + public function store(CreateUserRequest $request) + { + $input = $request->all(); + $User = $this->userRepo->create($input); + + Flash::success('User saved successfully.'); + return redirect(route('admin.users.index')); + } + + /** + * Display the specified User. + * + * @param int $id + * + * @return Response + */ + public function show($id) + { + $users = $this->userRepo->findWithoutFail($id); + + if (empty($users)) { + Flash::error('User not found'); + return redirect(route('admin.users.index')); + } + + return view('admin.users.show', [ + 'users' => $users, + ]); + } + + /** + * Show the form for editing the specified User. + * + * @param int $id + * + * @return Response + */ + public function edit($id) + { + $user = $this->userRepo->findWithoutFail($id); + + if (empty($user)) { + Flash::error('User not found'); + return redirect(route('admin.users.index')); + } + + return view('admin.users.edit', [ + 'user' => $user, + 'airports' => Airport::all()->pluck('icao', 'id'), + 'airlines' => Airline::all()->pluck('name', 'id'), + 'ranks' => Rank::all()->pluck('name', 'id'), + 'roles' => Role::all()->pluck('name', 'id'), + ]); + } + + /** + * Update the specified User in storage. + * + * @param int $id + * @param UpdateUserRequest $request + * + * @return Response + */ + public function update($id, UpdateUserRequest $request) + { + $user = $this->userRepo->findWithoutFail($id); + + if (empty($user)) { + Flash::error('User not found'); + return redirect(route('admin.users.index')); + } + + $req_data = $request->all(); + if($req_data['password'] == '') { + unset($req_data['password']); + } else { + $req_data['password'] = Hash::make($req_data['password']); + } + + $user = $this->userRepo->update($req_data, $id); + + DB::table('role_user')->where('user_id',$id)->delete(); + foreach ($request->input('roles') as $key => $value) { + $user->attachRole($value); + } + + Flash::success('User updated successfully.'); + return redirect(route('admin.users.index')); + } + + /** + * Remove the specified User from storage. + * + * @param int $id + * + * @return Response + */ + public function destroy($id) + { + $user = $this->userRepo->findWithoutFail($id); + + if (empty($user)) { + Flash::error('User not found'); + return redirect(route('admin.users.index')); + } + + $this->userRepo->delete($id); + + Flash::success('User deleted successfully.'); + return redirect(route('admin.users.index')); + } +} diff --git a/app/Http/Requests/CreateUserRequest.php b/app/Http/Requests/CreateUserRequest.php new file mode 100644 index 00000000..e4d71772 --- /dev/null +++ b/app/Http/Requests/CreateUserRequest.php @@ -0,0 +1,30 @@ + 'integer', ]; + /** + * Validation rules + * + * @var array + */ + public static $rules = [ + + ]; + public function pilot_id() { return $this->airline->icao.str_pad($this->id, 3, '0', STR_PAD_LEFT); diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php new file mode 100644 index 00000000..86a7712f --- /dev/null +++ b/app/Repositories/UserRepository.php @@ -0,0 +1,22 @@ + {!! Form::label('subfleet_id', 'Subfleet:') !!} - {!! Form::select('subfleet_id', $subfleets, null, ['class' => 'form-control', 'placeholder' => 'Select Subfleet']) !!} + {!! Form::select('subfleet_id', $subfleets, null, ['class' => 'form-control select2', 'placeholder' => 'Select Subfleet']) !!} diff --git a/resources/views/admin/aircraft/table.blade.php b/resources/views/admin/aircraft/table.blade.php index 093dabd3..3af6f877 100644 --- a/resources/views/admin/aircraft/table.blade.php +++ b/resources/views/admin/aircraft/table.blade.php @@ -18,7 +18,7 @@ - @endif - {!! $ac->name !!} + {!! $ac->name !!} {!! $ac->registration !!} @if($ac->active == 1) diff --git a/resources/views/admin/sidebar.blade.php b/resources/views/admin/sidebar.blade.php index d905d870..e49ce0a3 100644 --- a/resources/views/admin/sidebar.blade.php +++ b/resources/views/admin/sidebar.blade.php @@ -8,7 +8,9 @@