41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Team;
|
|
|
|
use App\Models\Truck;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class StoreTruckRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$truck = $this->route('truck');
|
|
$truckId = $truck instanceof Truck ? $truck->id : $truck;
|
|
|
|
$rules = [
|
|
'plate_number' => [
|
|
'required',
|
|
'string',
|
|
'max:16',
|
|
Rule::unique('trucks', 'plate_number')->ignore($truckId)->whereNull('deleted_at'),
|
|
],
|
|
'model' => ['nullable', 'string', 'max:100'],
|
|
'capacity_kg' => ['nullable', 'integer', 'min:0'],
|
|
'status' => ['nullable', Rule::in([Truck::STATUS_ACTIVE, Truck::STATUS_MAINTENANCE, Truck::STATUS_RETIRED])],
|
|
'notes' => ['nullable', 'string', 'max:1000'],
|
|
];
|
|
|
|
if (auth()->user()?->isSuperAdmin()) {
|
|
$rules['tenant_id'] = ['nullable', 'string', 'exists:tenants,uuid'];
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
}
|