2024-07-04 12:50:11 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
2024-07-04 14:37:58 -07:00
|
|
|
use App\Models\AssetModel;
|
2024-07-04 12:50:11 -07:00
|
|
|
use App\Models\Category;
|
2024-07-04 14:37:58 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2024-07-04 12:50:11 -07:00
|
|
|
|
|
|
|
class StoreAssetModelRequest extends ImageUploadRequest
|
|
|
|
{
|
2024-07-04 13:52:37 -07:00
|
|
|
|
2024-07-04 12:50:11 -07:00
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*/
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
2024-07-04 14:37:58 -07:00
|
|
|
return Gate::allows('create', new AssetModel);
|
2024-07-04 12:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareForValidation(): void
|
|
|
|
{
|
|
|
|
|
2024-07-04 13:14:58 -07:00
|
|
|
$this->category_type = Category::find($this->category_id)->category_type;
|
2024-07-04 13:52:37 -07:00
|
|
|
|
2024-07-04 12:50:11 -07:00
|
|
|
$this->merge([
|
2024-07-04 13:14:58 -07:00
|
|
|
'category_type' => $this->category_type,
|
2024-07-04 12:50:11 -07:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
|
|
*/
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return array_merge(
|
2024-07-04 13:14:58 -07:00
|
|
|
['category_type' => 'required|in:asset'],
|
2024-07-04 12:50:11 -07:00
|
|
|
parent::rules(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function messages(): array
|
|
|
|
{
|
2024-07-04 13:52:37 -07:00
|
|
|
$messages = ['category_type.in' => trans('admin/models/message.invalid_category_type')];
|
2024-07-04 12:50:11 -07:00
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
}
|