[Back] <?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class CustomerProfileController extends Controller
{
public function edit()
{
$user = auth()->user();
$profile = $user->customerProfile()->firstOrCreate(['user_id' => $user->id]);
return view('customer.profile.edit', compact('user', 'profile'));
}
public function update(Request $request)
{
$user = auth()->user();
$profile = $user->customerProfile()->firstOrCreate(['user_id' => $user->id]);
$data = $request->validate([
'phone' => ['nullable','string','max:30'],
'address_line1' => ['nullable','string','max:200'],
'address_line2' => ['nullable','string','max:200'],
'city' => ['nullable','string','max:100'],
'state' => ['nullable','string','max:100'],
'postcode' => ['nullable','string','max:20'],
'country' => ['nullable','string','max:2'],
]);
$profile->update($data);
return back()->with('success', 'Profile updated.');
}
}