2023-10-31 19:06:44 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
2023-11-28 13:17:46 -08:00
|
|
|
use App\Models\Company;
|
2023-10-31 19:06:44 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
class StoreAssetRequest extends ImageUploadRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
2023-11-01 09:33:29 -07:00
|
|
|
return Gate::allows('create', new Asset);
|
2023-10-31 19:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareForValidation(): void
|
|
|
|
{
|
2023-11-28 13:17:46 -08:00
|
|
|
$this->merge([
|
|
|
|
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
|
|
|
|
'company_id' => Company::getIdForCurrentUser($this->company_id),
|
|
|
|
]);
|
2023-10-31 19:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
$rules = array_merge(
|
|
|
|
(new Asset)->getRules(),
|
|
|
|
parent::rules(),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|