40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
use App\Http\Requests\ParentIDBaseRequest;
|
|
use App\Models\File;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class StoreFileRequest extends ParentIDBaseRequest
|
|
{
|
|
// authorization handled by ParentIDBaseRequest
|
|
|
|
/**
|
|
* 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(parent::rules(),
|
|
[
|
|
'files.*' => [
|
|
'required',
|
|
'file',
|
|
function ($attribute, $value, $fail) {
|
|
$file = File::query()
|
|
->where('name', $value->getClientOriginalName())
|
|
->where('created_by', Auth::id())
|
|
->where('parent_id', $this->parent_id)
|
|
->whereNull('deleted_at');
|
|
|
|
if ($file->exists()) {
|
|
$fail('File already exists.');
|
|
}
|
|
}
|
|
],
|
|
]);
|
|
}
|
|
}
|