logo
Tags down

shadow

Validation in Laravel 5.6


By : user2175381
Date : October 15 2020, 08:10 PM
hop of those help? You need to correct spell numaric to numeric and add nullable keyword in validation rule
code :
'coupon_title'          => 'string|max:10|nullable',
'coupon_type_id'        => 'numeric',
$messages = [
    'before_or_equal'    => 'The :attribute must be smaller than the End Date',
    'before'    => 'The :attribute must be Greater than the Interview Start Date',
    'after'    => 'The :attribute must be Greater than the Interview End Date',
    'after_or_equal'    => 'The :attribute must be Greater than the Start Time',
    'max' => 'The :attribute has crossed the limit',
    'numeric' => 'The :attribute must have numeric value'
];


Share : facebook icon twitter icon

Laravel Validation Login form validation fails in Password confimation?


By : AeronMan
Date : March 29 2020, 07:55 AM
I hope this helps you . I have two forms, login and signup forms, and one User model, i have set-up my rules and messages in User class, which are static members, $rules and $messages, the problem i face now, is in sign up form everything validate the it should be, but in login form, after i put a correct email and password, it gives me "Password confirmation doesn't match" which it shouldn't because there is no password_confrimation field in the login form. , I did like this in my project
code :
public static $rules = array(
                        'email'      => 'required|email|unique:users,email',
                        'password'   => 'required|min:6',
                        'repassword' => 'same:password',
                        'group'      => 'exists:groups,id',
                        'last_name'  => 'required',
                        'first_name' => 'required',
                       );

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


By : Zhang Yaming
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You want a custom validation rule, and I would create a separate class for this. But for brevity here's pretty much the same using inline closure:
code :
// give it meaningful name, I'll go with game_fixture as an example
Validator::extend('game_fixture', function ($attribute, $value, $parameters, $validator) 
{
    if (count($parameters) < 4)
    {
        throw new \InvalidArgumentException("Validation rule game_fixture requires 4 parameters.");
    }

    $input    = $validator->getData();
    $verifier = $validator->getPresenceVerifier();

    $collection = $parameters[0];
    $column     = $parameters[1];
    $extra      = [$parameters[2] => array_get($input, $parameters[3])];

    $count = $verifier->getMultiCount($collection, $column, (array) $value, $extra);

    return $count >= 1;
});
$rules = array(
    'game_id' => 'required|exists:games,id',

    // last parameter here refers to the 'game_id' value passed to the validator
    'team1_id' => 'required|game_fixture:teams,id,game_id,game_id',
    'team2_id' => 'required|game_fixture:teams,id,game_id,game_id'
);

Validation error in Laravel - $errors array does not get populated after the validation failure


By : PVM
Date : March 29 2020, 07:55 AM
Hope this helps If you are running Laravel 5.2.27 and up, you no longer need to use the web middleware group. In fact, you shouldn't add it to your routes because it's now automatically applied by default.
If you open up your app/Http/RouteServiceProvider.php file, you will see this bit of code:
code :
protected function mapWebRoutes(Router $router)
{
    $router->group([
        'namespace' => $this->namespace, 'middleware' => 'web',
    ], function ($router) {
        require app_path('Http/routes.php');
    });
}

show flash message on validation fails ( image validation ) (laravel)


By : Boso
Date : March 29 2020, 07:55 AM
it helps some times Just try to put FlashMessage in else and then try this.
Hope it helps
code :
public function update_avatar(Request $request,$username){
  $validator = Validator::make($request->all(), [
                'avatar' => 'mimes:jpeg,bmp,png|required'
            ]);
  if($validator->fails()){ 
    \Session::flash('message','Please choose a file first.');
    \Session::flash('alert-class', 'alert-warning'); 
    return redirect()->back();
  }
  if($request->hasFile('avatar')){
    $avatar = $request->file('avatar');
    $filename = time(). '.' . $avatar->getClientOriginalExtension();
    Image::make($avatar)->save('assets/src/uploads/avatars/' . $filename);
    $user = User::where('username', $username)->first();
    $user->avatar = $filename;
    $user->update();
  }
  return redirect()->route('myplace',['username' => $user->username]);
}

Laravel validation modify request before validation. return original if failed


By : siri
Date : March 29 2020, 07:55 AM
it helps some times Create a custom validator which strips the tags, counts characters but does not modify the content itself.
code :
Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) {

    $validator->addReplacer('strip_min', function($message, $attribute, $rule, $parameters){
        return str_replace([':min'], $parameters, $message);
    });

    return strlen(
        strip_tags(
            preg_replace(
                '/\s+/', 
                '', 
                str_replace('&nbsp;',"", $value)
            )
        )
    ) >= $parameters[0];
});
'strip_min' => 'The :attribute must be at least :strip_min characters.'   
Related Posts Related Posts :
  • Can't take screenshot in Laravel Dusk
  • Assigning user capability to read article on Laravel - article based permissions
  • XML to database - foreach loop to MySQL
  • Rotate the icons in the direction of the line
  • What would cause PHPMailer's $mail->send() to return false?
  • Transpose data from a mysql table
  • how to generate qr code with php 7.0 and laravel 5.5
  • Cannot include WooCommerce-CustomerClass to other PHP-File
  • Function Variable - API Response preg_split result and pass created variable to new function
  • How to add subitem totals to get groupitem total in laravel view
  • php how to get xml tags
  • how to execute a cmd in sql?
  • Mongo $addToSet an Array
  • Integrating isotope.js with Wordpress loop
  • Create Admin settings for SugarCRM custom module
  • Storing special characters in DB in such a way to display properly on site and still find image with the same name
  • Obtain value tag from xml
  • PHP Mail with attachment - but file is empty
  • PHP Multiple require, same function
  • Traverse XML file to find products recursively
  • PHP is not displaying 'success' message after writing data to JSON, but data gets added
  • Locate specific text in Google Sheets using the API
  • Laravel, convert to uuid text from uuid binary upon creating model
  • Creating formula
  • Grouped Array data
  • Wordpress get_option() with index key from string
  • PHP Laravel: A better way than these if statements
  • Trying to build my query by fetching column names from the selected table
  • Two values in the same column
  • Exceeding 10 nested forwards?
  • Ternary in associative arrays in PHP
  • simplexml_load_file won't fetch data with an Array
  • php mysql looking how to check if there are no result
  • Laravel filters won't work when trying to add them
  • Checking for duplicate mysql data with bootstrap validator
  • yii2 Error of dynamic client validation URL - Cannot read property 'test' of undefined
  • PHP Script to handle end of year calculation automatically?
  • Saved html is not the same as it's output in the browser
  • Wordpress shows only one post
  • SQL record retrieval
  • PHP return true if all method calls inside a foreach method return true
  • Unexpected error after transfering website to new server - mix of php and html in IF
  • Remove the last part of the comma in foreach in PHP?
  • the_author_meta() wont show inline text in { }
  • How do I create an error handler in php that redirects the user if a specific error occurs?
  • PHPInfo / Valet - Two different PHP versions
  • Connect an active directory or LDAP with PHP
  • How to assign a variable from another file to a class constant?
  • How to remove array index from php array?
  • How to handle multiple paginations with one link
  • Inverting order of exhibition of the elements in PHP
  • Slim 3 withRedirect problem and parameters
  • using Laravel 5.7 : how can i get json value name from an array ?
  • I See a Lot of `<open></close>` Tag Sets That Contain NO Data, Doesn't This Negate the Tag?
  • Calling a class and function using variable
  • php unset foreach loop is not unsetting the value of array
  • Error! The command "tesseract" was not found. (PHP thiagoalessio)
  • Get the catalog visibility for a product in a SQL query on Woocommerce
  • show data from json
  • Laravel - Views - router() doesn't work or I just dumb
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org