Files
GSB-Construction/app/Http/Controllers/ProfileController.php
Christopher Boyles 32c3e3af69
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled
Team Roster Feature
2026-06-08 17:45:15 +08:00

60 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\ProfileUpdateRequest;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
use Inertia\Response;
class ProfileController extends Controller
{
/**
* Display the user's profile form.
*/
public function edit(Request $request): Response
{
return Inertia::render('Profile/Edit', [
'mustVerifyEmail' => $request->user() instanceof MustVerifyEmail,
'status' => session('status'),
]);
}
/**
* Update the user's profile information.
*/
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$user = $request->user();
$validated = $request->validated();
$user->fill($validated);
if ($user->isDirty('email')) {
$user->email_verified_at = null;
}
if ($request->hasFile('profile_picture')) {
$file = $request->file('profile_picture');
$filename = time() . '_' . uniqid() . '.' . $file->getClientOriginalExtension();
$path = $file->storeAs('avatars', $filename, 'public');
// Delete old avatar if it exists
if ($user->profile_picture) {
$oldPath = str_replace('/storage/', '', $user->profile_picture);
\Illuminate\Support\Facades\Storage::disk('public')->delete($oldPath);
}
$user->profile_picture = '/storage/' . $path;
}
$user->save();
return Redirect::route('profile.edit')->with('success', 'Profile updated successfully.');
}
}