diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index 8c931225..e5d1ce4b 100755
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -110,7 +110,7 @@ class RegisterController extends Controller
{
$this->validate(request(), [
'name' => 'required',
- 'email' => 'required|unique:users|email',
+ 'email' => 'required|email|unique:users,email',
'airline_id' => 'required',
'home_airport_id' => 'required',
'password' => 'required|confirmed'
diff --git a/app/Http/Controllers/Frontend/ProfileController.php b/app/Http/Controllers/Frontend/ProfileController.php
index c1b350f5..8a1ada61 100644
--- a/app/Http/Controllers/Frontend/ProfileController.php
+++ b/app/Http/Controllers/Frontend/ProfileController.php
@@ -2,24 +2,39 @@
namespace App\Http\Controllers\Frontend;
-use App\Models\User;
-use App\Repositories\AirportRepository;
-use App\Http\Controllers\AppBaseController;
+use Log;
+use Hash;
+use Flash;
+use Validator;
+use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
+use Jackiedo\Timezonelist\Facades\Timezonelist;
+use App\Models\User;
+use App\Repositories\AirlineRepository;
+use App\Repositories\AirportRepository;
+use App\Repositories\UserRepository;
+use App\Http\Controllers\AppBaseController;
class ProfileController extends AppBaseController
{
- private $airportRepository;
+ private $airlineRepo,
+ $airportRepo,
+ $userRepo;
- public function __construct(AirportRepository $airportRepo)
- {
- $this->airportRepository = $airportRepo;
+ public function __construct(
+ AirlineRepository $airlineRepo,
+ AirportRepository $airportRepo,
+ UserRepository $userRepo
+ ) {
+ $this->airlineRepo = $airlineRepo;
+ $this->airportRepo = $airportRepo;
+ $this->userRepo = $userRepo;
}
public function index()
{
- $airports = $this->airportRepository->all();
+ $airports = $this->airportRepo->all();
return $this->view('profile.index', [
'user' => Auth::user(),
@@ -35,7 +50,7 @@ class ProfileController extends AppBaseController
return redirect(route('frontend.dashboard.index'));
}
- $airports = $this->airportRepository->all();
+ $airports = $this->airportRepo->all();
return $this->view('profile.index', [
'user' => $user,
@@ -43,8 +58,59 @@ class ProfileController extends AppBaseController
]);
}
- public function update()
+ /**
+ * Show the edit for form the user's profile
+ */
+ public function edit(Request $request)
{
+ $user = User::where('id', Auth::user()->id)->first();
+ if (empty($user)) {
+ Flash::error('User not found!');
+ return redirect(route('frontend.dashboard.index'));
+ }
+ $airlines = $this->airlineRepo->selectBoxList();
+ $airports = $this->airportRepo->selectBoxList();
+
+ return $this->view('profile.edit', [
+ 'user' => $user,
+ 'airlines' => $airlines,
+ 'airports' => $airports,
+ 'timezones' => Timezonelist::toArray(),
+ ]);
+ }
+
+ public function update(Request $request)
+ {
+ $id = Auth::user()->id;
+ $user = $this->userRepo->findWithoutFail($id);
+
+ $validator = Validator::make($request->toArray(), [
+ 'name' => 'required',
+ 'email' => 'required|unique:users,email,'.$id,
+ 'airline_id' => 'required',
+ 'password' => 'confirmed'
+ ]);
+
+ if ($validator->fails()) {
+ Log::info('validator failed for user '.$user->pilot_id);
+ Log::info($validator->errors()->toArray());
+
+ return redirect(route('frontend.profile.edit', $id))
+ ->withErrors($validator)
+ ->withInput();
+ }
+
+ $req_data = $request->all();
+ if (!$request->filled('password')) {
+ unset($req_data['password']);
+ } else {
+ $req_data['password'] = Hash::make($req_data['password']);
+ }
+
+ $user = $this->userRepo->update($req_data, $id);
+
+ Flash::success('Profile updated successfully!');
+ return redirect(route('frontend.profile.index'));
}
}
diff --git a/resources/views/layouts/default/app.blade.php b/resources/views/layouts/default/app.blade.php
index 1e9c12a6..d53528e7 100644
--- a/resources/views/layouts/default/app.blade.php
+++ b/resources/views/layouts/default/app.blade.php
@@ -4,8 +4,6 @@
-
-
@yield('title') - {!! config('app.name') !!}
+
+
edit your profile
+ @include('flash::message')
+ {!! Form::model($user, ['route' => ['frontend.profile.update', $user->id], 'method' => 'patch']) !!}
+ @include('layouts.default.profile.fields')
+ {!! Form::close() !!}
+
+
+@endsection
diff --git a/resources/views/layouts/default/profile/fields.blade.php b/resources/views/layouts/default/profile/fields.blade.php
index 9c6fa089..71377e3d 100644
--- a/resources/views/layouts/default/profile/fields.blade.php
+++ b/resources/views/layouts/default/profile/fields.blade.php
@@ -1,23 +1,78 @@
-
-
-
-
Update
- {!! Form::model($user, ['url' => url('/profile'), 'method' => 'post']) !!}
-