laravel-validation

Laravel Extended Validation custom message

筅森魡賤 提交于 2019-12-01 16:00:54
I wanted to create this extended validation. Validator::extend('my_custom_validation_rule', function ($attribute, $value, $parameters) { // I guess I should be setting the error message for this here.(Its dynamic) // We can return true or false here depending upon our need. } I would use this rule like this 'my_field' => 'required|my_custom_validation_rule' , I want to use some dynamic message for the error of " my_custom_validation_rule " I was unable to find something from the documentation about it. Is there anyway to do it ? The extend method allows to pass the message as a third argument:

Laravel preg_match(): Unknown modifier ']'

浪子不回头ぞ 提交于 2019-12-01 14:38:31
Im wokring on Laravel 4.2. Im trying to use validator to validate a name field with regex here is my rule below: public static $rules_save = [ 'name' => 'required|regex:/[XI0-9/]+/|unique:classes' ]; But as soon as I call the rule to be validated an error is thrown see below: preg_match(): Unknown modifier ']' In the following location: protected function validateRegex($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'regex'); return preg_match($parameters[0], $value); // **ON THIS LINE** } Since you need to include a / into the character class, you need to

Laravel 5 custom validation redirection

馋奶兔 提交于 2019-11-30 09:44:56
I have a website which consist of 2 different login form at 2 places, one on the navbar and the other one is a login page which will be used when the system catches an unlogged visitor. Can I ask what have I done wrong in my LoginRequest.php where I've set a condition to redirect to a custom login page if there is any sort of error in the login process? I have my codes as below: <?php namespace App\Http\Requests; use App\Http\Requests\Request; class LoginRequest extends Request { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() {

How to prevent insert email if already exist with specific id in laravel?

◇◆丶佛笑我妖孽 提交于 2019-11-29 15:16:57
I have table in which i'm trying to store email addresses. These email addresses will be save with user_id . For example in email_list table |ID | user_id | email | ............................... | 1 | 101 | john@gmail.com | ............................... | 2 | 102 | john@gmail.com | In above table you can see same email addresses save with different user_id , that's it what i'm trying to do. Currently i'm trying simple laravel validation like this. 'email' => 'required|unique:email_list|email', So is there any way to check already exist email addresses if row has same user_id ? I'm using

Laravel 5 custom validation redirection

家住魔仙堡 提交于 2019-11-29 09:17:26
问题 I have a website which consist of 2 different login form at 2 places, one on the navbar and the other one is a login page which will be used when the system catches an unlogged visitor. Can I ask what have I done wrong in my LoginRequest.php where I've set a condition to redirect to a custom login page if there is any sort of error in the login process? I have my codes as below: <?php namespace App\Http\Requests; use App\Http\Requests\Request; class LoginRequest extends Request { /** *

How add Custom Validation Rules when using Form Request Validation in Laravel 5

倖福魔咒の 提交于 2019-11-28 15:48:16
I am using form request validation method for validating request in laravel 5.I would like to add my own validation rule with form request validation method.My request class is given below.I want to add custom validation numeric_array with field items. protected $rules = [ 'shipping_country' => ['max:60'], 'items' => ['array|numericarray'] ]; My cusotom function is given below Validator::extend('numericarray', function($attribute, $value, $parameters) { foreach ($value as $v) { if (!is_int($v)) { return false; } } return true; }); How can use this validation method with about form request

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

假如想象 提交于 2019-11-27 20:45:58
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>' ); So with my validation rules I want to be able to make sure that: game_id exists within the games table

How to force FormRequest return json in Laravel 5.1?

别说谁变了你拦得住时间么 提交于 2019-11-27 19:45:19
I'm using FormRequest to validate from which is sent in an API call from my smartphone app. So, I want FormRequest alway return json when validation fail. I saw the following source code of Laravel framework, the default behaviour of FormRequest is return json if reqeust is Ajax or wantJson. //Illuminate\Foundation\Http\FormRequest class /** * Get the proper failed validation response for the request. * * @param array $errors * @return \Symfony\Component\HttpFoundation\Response */ public function response(array $errors) { if ($this->ajax() || $this->wantsJson()) { return new JsonResponse(

Laravel 5.2 validation errors

倾然丶 夕夏残阳落幕 提交于 2019-11-27 04:24:01
I have some trouble with validation in Laravel 5.2 When i try validate request in controller like this $this->validate($request, [ 'title' => 'required', 'content.*.rate' => 'required', ]); Validator catch error, but don't store them to session, so when i'm try to call in template this code @if (isset($errors) && count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif Laravel throw the error Undefined variable: errors (View: /home/vagrant/Code/os.dev/resources/views/semantic/index.blade.php) When i'm

Undefined variable: errors in Laravel

寵の児 提交于 2019-11-27 04:09:20
When I want to register a user in my laravel project, the page always says Undefined variable: errors (View: /var/www/resources/views/auth/register.blade.php)" According to the Laravel documentation, $errors should always automatically be set: So, it is important to note that an $errors variable will always be available in all of your views on every request, allowing you to conveniently assume the $errors variable is always defined and can be safely used. I have this on on every view when I use: @if (count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $error)