Skip to content

How do I validate an image field? #1212

Closed Answered by jcastroa87
backpack-operations asked this question in Q&A (Help)
Discussion options

You must be logged in to vote

Hello @backpack-operations

To validate the image field in Backpack, you have a couple of options:

  1. For the upload field type, Backpack provides a custom validation rule called ValidUpload. This makes validation easier, especially when dealing with create and update operations. You can use it like this:
use Backpack\CRUD\app\Library\Validation\Rules\ValidUpload;

'image' => ValidUpload::field('required')
                ->file('file|mimes:jpeg,png,jpg,gif,svg|max:2048'),

This rule allows you to define field rules and file rules separately, making it more convenient Docs > 6.x > Fields > FREE Field Types > upload.

  1. However, for the image field type specifically, which sends a base64 string…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by backpack-operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants