laravel-validation

Laravel validation: exists with additional column condition - custom validation rule

冷暖自知 提交于 2019-12-17 15:57:35
问题 Is there is a way of referencing another field when specifying the exists validation rule in Laravel? I want to be able to say that input a must exist in table a, input b must exist in table b AND the value for column x in table b must equal input a. Best explained by example: public $rules = array( 'game_id' => 'required|exists:games,id', 'team1_id' => 'required|exists:teams,id,game_id,<game_id input value here>', 'team2_id' => 'required|exists:teams,id,game_id,<game_id input value here>' );

How to pass the value inside the model for checking in the rules

◇◆丶佛笑我妖孽 提交于 2019-12-13 07:42:26
问题 I am trying to have this rules in my model 'Email' => 'email|unique:tablename,coloumntoignore,ignoreid', The above rules is to check the unique coloumn except the id to be supplied in the ignoreid I face two issues here I am getting the user input $DriverData = Input::except(array('_token')); and sending it to the model $validation = Validator::make($DriverData, DriverModel::$updaterules); Note : This update is not the self so i can't get it by Auth::user()->id and my primary key is not id I

How to check file is uploaded or not in laravel

徘徊边缘 提交于 2019-12-13 01:28:30
问题 I am uploading an image file to the input file ImageUpload .I need to check if file has been uploaded then create a unique filename and save it on the server. $file = $request->file('ImageUpload'); $filename=uniqid($user->id . '_' ).".".$file->getClientOriginalExtension(); Storage::disk('public')->put($filename,File::get($file)); 回答1: You can check if your file variable exists as if($request->hasFile('ImageUpload')){ } But, as per official documentation, to check whether file upload is

Laravel validation: unique rule 4th parameter

…衆ロ難τιáo~ 提交于 2019-12-12 04:57:00
问题 Having a look through the Laravel docs, API documents and source code I am wondering if anyone knows what the 4th parameter id in the following unique rule is for? 'email' => 'unique:users,email_address,NULL,id,account_id,1' My current understanding of this rule is: users - looking in this table email_address - checking against this column NULL - would be where we could specify a primary key/ID value to ignore, but we haven't bothered so this parameter is essentially ignored id - unsure

Object of class Illuminate\Validation\Validator could not be converted to string

跟風遠走 提交于 2019-12-12 01:37:45
问题 I'm yet to understand what needed to be fixed in the code making it to generate the error. What is to be put right? This is the code: public function store(Request $request){ $validator = Validator::make($request->all(), [ 'user_id' => 'required|numeric', 'company_id' => 'required|numeric', 'product_id' => 'required|numeric', 'tankerTotankerDesc' => 'alpha_num|min:5', 'tankerTakeOverDesc' => 'alpha_num|min:5', 'costFreightInsuranceDesc' => 'alpha_num|min:5', 'freightOnBoardDesc' => 'alpha_num

How to get validation message in laravel 5.5

会有一股神秘感。 提交于 2019-12-10 15:41:18
问题 hi folks I'm working on Laravel 5.5 and here I need to display validation messages for my API upto now I have done like this $validator = Validator::make($request->all(),[ 'first_name' => 'email|required', 'last_name' => 'nullable', 'email' => 'email|required', 'mobile_no' => 'nullable|regex:/^[0-9]+$/', 'password' => 'required', ]); if($validator->fails) { $this->setMeta('status', AppConstant::STATUS_FAIL); $this->setMeta('message', $validator->messages()->first()); return response()->json(

Displaying validation errors in Laravel 5 with React.js and Ajax

孤街醉人 提交于 2019-12-10 13:07:46
问题 I am running a Laravel 5 application that has its main view rendered using React.js. On the page, I have a simple input form, that I am handling with Ajax (sending the input back without page refresh). I validate the input data in my UserController. What I would like to do is display error messages (if the input does not pass validation) in my view. I would also like the validation errors to appear based on state (submitted or not submitted) within the React.js code. How would I do this using

How to validate multiple email in laravel validation?

♀尐吖头ヾ 提交于 2019-12-09 04:44:54
问题 I have done all the things for the validation for the variable in laravel but for emails I got one simple problem. From doc of Laravel, 'email' => 'required|email' I got to know this is for only one email address but for like, email=abc@xyz.com,xyz@abc.com, def@ghi,com When I send array of the email i still get email is not a valid email. I have done more like, 'email' => 'required|email|array' But I still got error. can any body help. Thanks, 回答1: You need to write custom Validator, which

How to make validation rules for storing and update users if there are unique attributes

蓝咒 提交于 2019-12-08 13:34:53
问题 I use username as an id to login and made username and email as unique. Whenever I made username and email, validation rules check coming data and there is no problem with it because username and email would be new and unique. The problem occurs when I update. when I update the attributes, I don't need to change the username mostly but the rules are expecting unique, username . what is the best practice for updating unique attributes with validation rules? . Update user method public function

How to validate a email address domain in Laravel?

左心房为你撑大大i 提交于 2019-12-07 15:57:34
问题 In Laravel, how do I validate an email address and force it to have a suffix like g.go.edu ? 回答1: If you want to accept all emails that have suffix g.go.edu , you can use as rule both email and regex rules, for example: $rules['email'] = ['email', 'regex:/(.*)g\.go\.edu$/i']; 来源: https://stackoverflow.com/questions/29720750/how-to-validate-a-email-address-domain-in-laravel