34 lines
984 B
PHP
34 lines
984 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Http\Requests\ParentId;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class SelectedFiles extends ParentId
|
|
{
|
|
// auth handled by ParentId
|
|
|
|
protected function prepareForValidation() {
|
|
// cast to boolean
|
|
$this->merge([
|
|
'all' => filter_var($this->all, FILTER_VALIDATE_BOOL),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
// append rules to default validation rules
|
|
return array_merge(parent::rules(), [
|
|
'all' => 'bool', // all or not
|
|
'Ids.*' => Rule::exists('files', 'id') // check that file exists in database
|
|
->where(fn($query) => $query->where('created_by', Auth::id())) // check file was made by current user
|
|
]);
|
|
}
|
|
}
|