I have in my app a simple form to upload photo.
There are three fields: title - caption - and the button for choosing the file. Right now the validation check if the title is required. The caption is not required and is ok.
But i do not know how can i deal with validation regarding files.
If no file is inserted, i get the laravel error message: Call to a member function move() on a non-object. Instead i would like just a validation error. And how can i required that only images are entered? Right now is possible to upload even word documents..
There are the rules as they are now. In the Photo model:
class Photo extends Eloquent {
protected $guarded = array();
public static $rules = array('title' => 'required');
}
Thank you!
Well 1st of all your
$rules
should be inPhotos
Model not in the controller , 2nd to make a file required you do it like so :you can add more rules like max file size like so :