46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use AllowDynamicProperties;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
#[AllowDynamicProperties]
|
|
class StoreCustomerProfileRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
// If this request is by a customer profile, then only allow the owner to update it.
|
|
if (isset($this->profile)) {
|
|
$this->user = $this->profile;
|
|
|
|
return $this->user()->id === $this->profile->id;
|
|
}
|
|
|
|
// If this request is by an admin, then allow them to update any profile.
|
|
$this->user = $this->customer->user;
|
|
|
|
return $this->user()->isAdmin();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => 'required|string|min:3|max:255',
|
|
'bio' => 'required|string|min:10|max:255',
|
|
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($this->user->id)],
|
|
'phone' => 'required|string|min:10|max:255',
|
|
'location' => 'required|string|min:3|max:255',
|
|
];
|
|
}
|
|
}
|