-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathCreateEntityRequest.php
More file actions
46 lines (42 loc) · 1.85 KB
/
Copy pathCreateEntityRequest.php
File metadata and controls
46 lines (42 loc) · 1.85 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
<?php
namespace Fleetbase\FleetOps\Http\Requests;
use Fleetbase\Http\Requests\FleetbaseRequest;
use Illuminate\Validation\Rule;
class CreateEntityRequest extends FleetbaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return 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
{
return [
'name' => [Rule::requiredIf($this->isMethod('POST'))],
'type' => [Rule::requiredIf($this->isMethod('POST'))],
'destination' => ['nullable', Rule::exists('places', 'public_id')->whereNull('deleted_at')],
'waypoint' => ['nullable', Rule::exists('places', 'public_id')->whereNull('deleted_at')],
'payload' => ['nullable', Rule::exists('payloads', 'public_id')->whereNull('deleted_at'), 'required_with:destination,waypoint'],
'email' => ['nullable', 'email'],
'weight' => 'nullable',
'weight_unit' => [Rule::requiredIf($this->has('weight')), 'in:g,oz,lb,kg'],
'length' => 'nullable',
'width' => 'nullable',
'height' => 'nullable',
'dimensions_unit' => [Rule::requiredIf($this->has(['length', 'width', 'height'])), 'in:cm,in,ft,mm,m,yd'],
'declared_value' => ['nullable', 'numeric'],
'price' => ['nullable', 'numeric'],
'sales_price' => ['nullable', 'numeric'],
'currency' => [Rule::requiredIf($this->has(['declared_value', 'price', 'sales_price'])), 'size:3'],
];
}
}