MIF_E31221259/app/Http/Controllers/User/ProfileAPHController.php

50 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;
class ProfileAPHController extends Controller
{
/**
* Display the user's profile.
*/
public function show()
{
$user = Auth::user();
return view('user.profile', compact('user'));
}
/**
* Show the form for editing the user's profile.
*/
public function edit()
{
$user = Auth::user();
return view('user.profile.edit', compact('user'));
}
/**
* Update the user's profile.
*/
public function update(Request $request)
{
$user = Auth::user();
$data = $request->validate([
'name' => ['required', 'string', 'max:100'],
'email' => ['required', 'email', 'max:100', Rule::unique('users')->ignore($user->id)],
'username' => ['required', 'string', 'max:50', Rule::unique('users')->ignore($user->id)],
'no_hp' => ['nullable', 'string', 'max:15'],
]);
$user->update($data);
return redirect()->route('user.profile.show')
->with('success', 'Profile updated successfully.');
}
}