-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathModifyRequest.php
More file actions
34 lines (27 loc) · 788 Bytes
/
Copy pathModifyRequest.php
File metadata and controls
34 lines (27 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace App\Http\Requests\User;
use App\Models\User;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Foundation\Http\FormRequest;
class ModifyRequest extends FormRequest
{
public function authorize(Gate $gate) : bool
{
$auth = $gate->allows('modify-user', $this->route()->parameter('id'));
return $auth;
}
public function rules(): array
{
return [
'name'=>'filled',
'email'=>'filled|unique:users,email,'.$this->route()->parameter('id').',id',
'password'=>['string', 'min:8', 'filled'],
];
}
public function modifyUser(): User
{
$user = new User($this->validated());
$user->id = (int) $this->route()->parameter('id');
return $user;
}
}