Answers for "laravel validation with error message"

PHP
1

get message validator failed laravel

$errors = $validator->errors()->getMessages();
Posted by: Guest on May-19-2021
9

laravel validator make custom message

$rules = [
        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required|max:250',
    ];

    $customMessages = [
        'required' => 'The :attribute field is required.'
    ];

    $this->validate($request, $rules, $customMessages);
Posted by: Guest on May-06-2020
1

validation error message in laravel

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
Posted by: Guest on August-04-2021
0

add error to laravel validation

//setup Validator and passing request data and rules
$validator = \Validator::make(request()->all(), [
    'due_date' => 'required',
    'template' => 'required'
]);

//hook to add additional rules by calling the ->after method
$validator->after(function ($validator) {
	
    if (request('event') == null) {
    	//add custom error to the Validator
        $validator->errors()->add('event', 'Please select an event');
    }

});

//run validation which will redirect on failure
$validator->validate();

//https://dcblog.dev/laravel-adding-custom-validation-errors
Posted by: Guest on April-27-2021
0

laravel validation custom message example

$rules = [
        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required|max:250',
    ];

    $customMessages = [
        'required' => 'The :attribute field is required.'
    ];

    $this->validate($request, $rules, $customMessages);
//@sujay
Posted by: Guest on November-30-2020
0

laravel select validation error messages

<div class="form-group">
<select id="province" name="province" class="form-control @error('province') is-invalid @enderror" >
                                        <option>Choose...</option>
                                        <option value="Western Cape" {{ ($user->learner->province == "Western Cape") ? 'selected' : ''}}>Western Cape</option>
                                        <option value="Northern Cape" {{ ($user->learner->province == "Northern Cape") ? 'selected' : '' }}>Northern Cape</option>
                                        <option value="Eastern Cape" {{ ($user->learner->province == "Eastern Cape") ? 'selected' : '' }}>Eastern Cape</option>
                                        <option value="North West" {{ ($user->learner->province == "North West") ? 'selected' : '' }}>North West</option>
                                        <option value="Free State" {{ ($user->learner->province == "Free State") ? 'selected' : '' }}> Free State</option>
                                        <option value="Kwazulu Natal" {{ ($user->learner->province == "Kwazulu Natal") ? 'selected' : '' }}>Kwazulu Natal</option>
                                        <option value="Gauteng" {{ ($user->learner->province == "Gauteng") ? 'selected' : '' }}>Gauteng</option>
                                        <option value="Limpopo" {{ ($user->learner->province == "Limpopo") ? 'selected' : '' }}>Limpopo</option>
                                        <option value="Mpumalanga" {{ ($user->learner->province == "Mpumalanga") ? 'selected' : '' }}>Mpumalanga</option>
                                    </select>
                                    @error('province')
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $message }}</strong>
                                        </span>
                                    @enderror
                                </div>
Posted by: Guest on June-20-2021

Code answers related to "laravel validation with error message"

Browse Popular Code Answers by Language