mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-27 06:29:47 -08:00
0d6fd2643d
Signed-off-by: snipe <snipe@snipe.net>
57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\AssetModel;
|
|
use App\Models\Category;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class StoreAssetModelRequest extends ImageUploadRequest
|
|
{
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return Gate::allows('create', new AssetModel);
|
|
}
|
|
|
|
public function prepareForValidation(): void
|
|
{
|
|
|
|
if ($this->category_id) {
|
|
if ($category = Category::find($this->category_id)) {
|
|
$this->merge([
|
|
'category_type' => $category->category_type ?? null,
|
|
]);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 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(
|
|
['category_type' => 'in:asset'],
|
|
parent::rules(),
|
|
);
|
|
}
|
|
|
|
public function messages(): array
|
|
{
|
|
$messages = ['category_type.in' => trans('admin/models/message.invalid_category_type')];
|
|
return $messages;
|
|
}
|
|
|
|
public function response(array $errors)
|
|
{
|
|
return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag);
|
|
}
|
|
}
|