2024-02-26 12:32:50 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
class UpdateAssetRequest extends ImageUploadRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
return Gate::allows('update', new Asset);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareForValidation()
|
|
|
|
{
|
|
|
|
// the following are 'required' attributes that may or may not be present on an patch request
|
|
|
|
// so supplying them here instead of doing funky array modification to the rules
|
2024-03-08 16:24:41 -08:00
|
|
|
return $this->merge([
|
|
|
|
'asset_tag' => $this->asset_tag ?? $this->asset->asset_tag,
|
|
|
|
'model_id' => $this->model_id ?? $this->asset->model_id,
|
|
|
|
'status_id' => $this->status_id ?? $this->asset->status_id,
|
2024-02-26 12:32:50 -08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
$rules = array_merge(
|
|
|
|
(new Asset())->getRules(),
|
|
|
|
parent::rules(),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|