-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathCreateDriverRequest.php
More file actions
60 lines (54 loc) · 2.09 KB
/
Copy pathCreateDriverRequest.php
File metadata and controls
60 lines (54 loc) · 2.09 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Fleetbase\FleetOps\Http\Requests;
use Fleetbase\FleetOps\Rules\ResolvablePoint;
use Fleetbase\Http\Requests\FleetbaseRequest;
use Illuminate\Validation\Rule;
class CreateDriverRequest extends FleetbaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return request()->is('navigator/v1/*') || request()->session()->has('api_credential') || request()->session()->has('is_sanctum_token');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$isCreating = $this->isMethod('POST');
return [
'name' => [Rule::requiredIf($isCreating)],
'email' => [Rule::requiredIf($isCreating), Rule::when($this->filled('email'), ['email']), Rule::when($isCreating, [Rule::unique('users')->whereNull('deleted_at')])],
'phone' => [Rule::requiredIf($isCreating), Rule::when($isCreating, [Rule::unique('users')->whereNull('deleted_at')])],
'password' => 'nullable|string',
'country' => 'nullable|size:2',
'city' => 'nullable|string',
'vehicle' => 'nullable|string|starts_with:vehicle_|exists:vehicles,public_id',
'license_expiry' => 'nullable|date',
'status' => 'nullable|string|in:active,available,inactive',
'vendor' => 'nullable|exists:vendors,public_id',
'job' => 'nullable|exists:orders,public_id',
'location' => ['nullable', new ResolvablePoint()],
'latitude' => ['nullable', 'required_with:longitude'],
'longitude' => ['nullable', 'required_with:latitude'],
];
}
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'email' => 'email address',
'phone' => 'phone number',
];
}
}