42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin\Profile;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Http\Requests\Admin\Profile\UpdateProfileRequest;
|
||
|
|
use App\Services\ProfileService;
|
||
|
|
use Illuminate\Support\Facades\Auth;
|
||
|
|
use Exception;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Handle Profile Update requests.
|
||
|
|
*
|
||
|
|
* @package App\Http\Controllers\Admin\Profile
|
||
|
|
*/
|
||
|
|
class ProfileUpdateController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Handle the incoming request.
|
||
|
|
*
|
||
|
|
* @param UpdateProfileRequest $request
|
||
|
|
* @param ProfileService $profileService
|
||
|
|
* @return \Illuminate\Http\RedirectResponse
|
||
|
|
*/
|
||
|
|
public function __invoke(UpdateProfileRequest $request, ProfileService $profileService)
|
||
|
|
{
|
||
|
|
$user = Auth::user();
|
||
|
|
|
||
|
|
try {
|
||
|
|
if ($profileService->update($user, $request->validated())) {
|
||
|
|
return redirect()
|
||
|
|
->route('admin.profile.edit')
|
||
|
|
->with('status', 'profile-updated');
|
||
|
|
}
|
||
|
|
} catch (Exception $e) {
|
||
|
|
return back()->withInput()->withErrors(['error' => $e->getMessage()]);
|
||
|
|
}
|
||
|
|
|
||
|
|
return back()->withInput()->with('error', 'Failed to update profile.');
|
||
|
|
}
|
||
|
|
}
|