I am doing all the validations in ModelMy Rule is public static $rules = array( 'VehicleNumber' => 'required|unique:vehicle', 'NumberSeats' => 'required', 'VehicleType' => 'required', 'MaximumAllowed' => 'numeric|max:3', 'VehicleCode' => 'required|unique:vehicle');}But for changing the file name and checking its size i am handling in a SetFooAttributepublic function setInsurancePhotoAttribute($InsurancePhoto){ if($InsurancePhoto && Input::file('InsurancePhoto')->getSize() < '1000') { $this->attributes['InsurancePhoto'] = Input::get('VehicleCode') . '-InsurancePhoto.' . Input::file('InsurancePhoto')->getClientOriginalExtension(); Input::file('InsurancePhoto')->move('assets/uploads/vehicle/', Input::get('VehicleCode') . '-InsurancePhoto.' . Input::file('InsurancePhoto')->getClientOriginalExtension()); }}There in the Conditionif($InsurancePhoto && Input::file('InsurancePhoto')->getSize() < '1000')If it fails the Storing of Image, Setting Attribute won't be done.But How can i throw the Error to the User in this Case ? 解决方案 getSize() return integer so you should not use string for comparison as you have written 1000 in single quotes. You can create your own custom Validation in laravel. Check this links stackoverflow and http://culttt.com/2014/01/20/extending-laravel-4-validator/ 这篇关于如果条件失败,Laravel会从模型抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-07 13:27