diff --git a/app/Http/Controllers/ClientPortal/ProfileController.php b/app/Http/Controllers/ClientPortal/ProfileController.php index 474bd8973994..85db14345032 100644 --- a/app/Http/Controllers/ClientPortal/ProfileController.php +++ b/app/Http/Controllers/ClientPortal/ProfileController.php @@ -13,8 +13,11 @@ namespace App\Http\Controllers\ClientPortal; use App\Http\Controllers\Controller; use App\Http\Requests\ClientPortal\UpdateContactRequest; +use App\Jobs\Util\UploadAvatar; use App\Models\ClientContact; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Log; class ProfileController extends Controller { @@ -59,10 +62,31 @@ class ProfileController extends Controller */ public function update(UpdateContactRequest $request, ClientContact $client_contact) { - //dd($client_contact); - tap($client_contact)->update($request->all()); - return view('portal.default.profile.index'); + $client_contact->fill($request->all()); + + //update password if needed + if($request->input('password')) + $client_contact->password = Hash::make($request->input('password')); + + //update avatar if needed + if($request->file('avatar')) + { + $path = UploadAvatar::dispatchNow($request->file('avatar'), auth()->user()->client->client_hash); + + if($path) + { + $client_contact->avatar = $path; + $client_contact->avatar_size = $request->file('avatar')->getSize(); + $client_contact->avatar_type = $request->file('avatar')->getClientOriginalExtension(); + } + } + + $client_contact->save(); + + // auth()->user()->fresh(); + + return back(); } } diff --git a/app/Jobs/Util/UploadAvatar.php b/app/Jobs/Util/UploadAvatar.php new file mode 100644 index 000000000000..2d0817232817 --- /dev/null +++ b/app/Jobs/Util/UploadAvatar.php @@ -0,0 +1,55 @@ +file = $file; + $this->directory = $directory; + } + + public function handle() : ?string + { + + //make dir + Storage::makeDirectory('public/' . $this->directory, 0755); + + //upload file + $path = Storage::putFile('public/' . $this->directory, $this->file); + + $url = Storage::url($path); + + //return file path + if($url) + return $url; + else + return null; + + } +} \ No newline at end of file diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 71bab7d09322..c35d2fb846ae 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -75,7 +75,6 @@ class ClientContact extends Authenticatable 'custom_value3', 'custom_value4', 'email', - 'avatar', ]; /**/ diff --git a/resources/views/portal/default/profile/index.blade.php b/resources/views/portal/default/profile/index.blade.php index e7145b76d70b..937283be4f6a 100644 --- a/resources/views/portal/default/profile/index.blade.php +++ b/resources/views/portal/default/profile/index.blade.php @@ -1,111 +1,108 @@ @extends('portal.default.layouts.master') @push('css') - - - + @endpush @section('body') -
+
-
+
-
- -
+
+ +
- {!! Former::framework('TwitterBootstrap4'); !!} + {!! Former::framework('TwitterBootstrap4'); !!} - {!! Former::horizontal_open() - ->id('update_contact') - ->route('client.profile.update', auth()->user()->hashed_id) - ->method('PUT'); !!} - - @csrf + {!! Former::vertical_open_for_files() + ->id('update_contact') + ->route('client.profile.update', auth()->user()->hashed_id) + ->method('PUT'); !!} + + @csrf -
+
-
- - {{ ctrans('texts.avatar') }} +
+ + {{ ctrans('texts.avatar') }} -
+
-
+
- @if(auth()->user()->avatar) - - @else - - @endif + @if(auth()->user()->avatar) + + @else + + @endif + {!! Former::file('avatar') + ->max(2, 'MB') + ->accept('image') + ->label('') + ->inlineHelp(trans('texts.logo_help')) !!} - {!! Former::file('avatar') - ->max(2, 'MB') - ->accept('image') - ->label(trans('texts.avatar')) - ->inlineHelp(trans('texts.logo_help')) !!} +
-
+ - +
-
+
+ +
-
+
+ + {{ ctrans('texts.user_details') }} -
+
-
- -
+
+ + {!! Former::text('first_name')->placeholder( ctrans('texts.first_name'))->label('')->value(auth()->user()->first_name)!!} -
- - {{ ctrans('texts.user_details') }} + {!! Former::text('last_name')->placeholder( ctrans('texts.last_name'))->label('')->value(auth()->user()->last_name) !!} -
+ {!! Former::text('email')->placeholder( ctrans('texts.email'))->label('')->value(auth()->user()->email) !!} -
- - {!! Former::text('first_name')->placeholder( ctrans('texts.first_name'))->label('')->value(auth()->user()->first_name)!!} + {!! Former::text('phone')->placeholder( ctrans('texts.phone'))->label('')->value(auth()->user()->phone) !!} - {!! Former::text('last_name')->placeholder( ctrans('texts.last_name'))->label('')->value(auth()->user()->last_name) !!} + {!! Former::password('password')->placeholder( ctrans('texts.password'))->label('') !!} - {!! Former::text('email')->placeholder( ctrans('texts.email'))->label('')->value(auth()->user()->email) !!} + {!! Former::password('password_confirmed')->placeholder( ctrans('texts.confirm_password'))->label('') !!} - {!! Former::text('phone')->placeholder( ctrans('texts.phone'))->label('')->value(auth()->user()->phone) !!} +
- {!! Former::password('password')->placeholder( ctrans('texts.password'))->label('') !!} + +
- - + {!! Former::close() !!} -
+
-
+
- {!! Former::close() !!} +
-
- -
- -
- -
+
@endsection \ No newline at end of file diff --git a/routes/client.php b/routes/client.php index d1d612da7232..68d13207ad47 100644 --- a/routes/client.php +++ b/routes/client.php @@ -17,7 +17,7 @@ Route::group(['middleware' => ['auth:contact'], 'prefix' => 'client', 'as' => 'c Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index'); // name = (dashboard. index / create / show / update / destroy / edit Route::get('profile/{client_contact}/edit', 'ClientPortal\ProfileController@edit')->name('profile.edit'); - Route::put('profile/{client_contact}', 'ClientPortal\ProfileController@update')->name('profile.update'); + Route::put('profile/{client_contact}/edit', 'ClientPortal\ProfileController@update')->name('profile.update'); Route::post('document', 'ClientPortal\DocumentController@store')->name('document.store'); Route::delete('document', 'ClientPortal\DocumentController@destroy')->name('document.destroy');