Answers for "validator laravel"

PHP
2

laravel validate integer between

'item' => 'required|integer|between:1,10',
Posted by: Guest on October-21-2020
3

email validation in laravel

'email' => 'required|email|unique:users,email',
//@sujay
Posted by: Guest on October-09-2020
6

validator laravel

public function store(Request $request)
{
    $validator = Validator::make($request->all(), [
        'title' => 'bail|required|max:255',
        'body' => 'required',
    ]);

    // Check validation failure
    if ($validator->fails()) {
       // [...]
      
      foreach($validator->messages()->getMessages() as $field_name => $messages) {

                // Go through each message for this field.
                foreach($messages AS $message) {
                    echo '***********'.$message.'***********<br>';
                }
            }
    }

    // Check validation success
    if ($validator->passes()) {
       // [...]
    }

    // Retrieve errors message bag
    $errors = $validator->errors();
}
Posted by: Guest on June-29-2021
8

if any error in blade laravel

@if ($errors->any())
     @foreach ($errors->all() as $error)
         <div>{{$error}}</div>
     @endforeach
 @endif
Posted by: Guest on November-01-2020
5

validate laravel

$validatedData = $request->validate([
    'title' => ['required', 'unique:posts', 'max:255'],
    'body' => ['required'],
]);
Posted by: Guest on January-06-2021
1

how to add an custom error to validater error in laravel

if (request('event') == null) {
    $validator->errors()->add('event', 'Please select an event');
}
Posted by: Guest on October-20-2020

Browse Popular Code Answers by Language