Some Backpack fields are more difficult to validate using standard Laravel validation rules. So we've created a few custom validation rules, that will make validation them dead-simple.
ValidUpload
for upload
field typeThe ValidUpload
rule is used to validate the upload
field type. Using the custom rule helps developer avoid to setting different validation rules for different operations, (create/update).
// for the field
CRUD::field('avatar')->type('upload');
// you can write the validation rule as
use Backpack\CRUD\app\Library\Validation\Rules\ValidUpload;
'avatar' => ValidUpload::field('required')->file('mimes:jpg,png|max:2048'),
The ::field()
constructor accepts the rules for the field, while ->file()
accepts the specific rules for files sent in field. The validation rule handles the sometimes
case for you.
ValidUploadMultiple
for upload_multiple
field typeYou can use this validation rule to handle validation for your upload_multiple
field - both for the Create and the Update operation in one go:
::field()
constructor to define the rules for the field;->file()
method for rules specific to the files sent in field;// for the field
CRUD::field('attachments')->type('upload_multiple');
// you can write the validation rule as
use Backpack\CRUD\app\Library\Validation\Rules\ValidUploadMultiple;
'attachments' => ValidUploadMultiple::field(['min:2', 'max:5'])->file('mimes:pdf|max:10000'),
ValidDropzone
for dropzone
field typeYou can use this validation rule to handle validation for your dropzone
field - both for the Create and the Update operation in one go:
::field()
constructor to define the rules for the field;->file()
method for rules specific to the files sent in field;// for the field
CRUD::field('photos')->type('dropzone');
// you can write the validation rule as
use Backpack\Pro\Uploads\Validation\ValidDropzone;
'attachments' => ValidDropzone::field('min:2|max:5')->file('file|mimes:jpg,png,gif|max:10000'),
Then you'll love our premium add-ons - productivity tools and tons of new features.