How do you validate a required upload field. When you set a validation on the field name with an existing value then an the required error shows but there is a value for the field.?
I found a solution to this. On create use the "required" rule. On update us the "file" rule. This ensures that a file must be attached. I would recommend adding this to the documentation.
@kevinab thanks for sharing your solution. Will definitely help others that search ;-) Cheers!
@kevinab how do you set different rules for each request?
@diegoc327 you can have different validation rules in your create and update methods. I don't put my rules in the request class.
@diegoc327 you can create a separate FormRequest file for Store, and another for Update. By default generated CRUDs ship with just one, but you should be able to easily duplicate the one you have, rename it and reuse it in your EntityCrudController. For example, by default you'd have MonsterRequest which is used for both Store and Update:

But you can:
app/Http/Requests;StoreMonsterRequest.php;UpdateMonsterRequest.php;MonsterCrudController appropriately:-use App\Http\Requests\MonsterRequest as StoreRequest;
+use App\Http\Requests\StoreMonsterRequest as StoreRequest;
-use App\Http\Requests\MonsterRequest as UpdateRequest;
+use App\Http\Requests\UpdateMonsterRequest as UpdateRequest;
Backpack will then pick up different requests for the Store and Update operations.
Hope it helps you or someone else that searches the same thing.
Cheers!
thank you very much @tabacitu very helpful!
I created two new files
CreateProductoRequest.php
UpdateProductoRequest.php
Modify ProductoCrudController to:
//use App\Http\Requests\ProductoRequest as StoreRequest;
//use App\Http\Requests\ProductoRequest as UpdateRequest;
use App\Http\Requests\CreateProductoRequest as StoreRequest;
use App\Http\Requests\UpdateProductoRequest as UpdateRequest;
Also I deleted ProductoRequest.php file
But I get 403 error when run Create or Update products
Seems is forbidden access, perhaps I need declare them in Routes/backpack/custom.php?
@Manolek1975 I don't think the 403 error is related to the FormRequests. I recommend you look at other changes you've made. The error page should give the exact line where the 403 error is triggered.
I really only made those changes, created the two files, and modified the use clauses, in fact I just reverted the changes and with ProductRequest.php it works perfectly, except my problem with unique and Update, I need separate rules for store and update
Page error only show "ERROR 403 Forbidden. This action is unauthorized."
Laravel log, don't show any error =(
Sorry I got error finally, I created files with artisan
php artisan make:request CreateProductoRequest.php
This way function authorized return false, I change function to:
public function authorize()
{
return backpack_auth()->check();
}
and now works, sorry for waste your time @tabacitu
Most helpful comment
I found a solution to this. On create use the "required" rule. On update us the "file" rule. This ensures that a file must be attached. I would recommend adding this to the documentation.