Support the ongoing development of →
Requests Validation Laravel
Last updated 2 years ago.

I have the same isue. Running latest Laravel 6.

I have tried this in my controller: $mValidatedData = $pRequest -> validate( $mRules, $mRuleMessages ); but that doesn't display any error messages in the form when directed back to the form. Although validation fails, and the $errors is being populated, when it gets to generating the view the _$errors _is empty.


Well, It looks like you are not doing anything with the method after validation. That block of code doesnt give too much information, but I can tell you 3 things.

1- You need to redirect to the view after the $model->save(); method.

2- You need to add a div on the form to display the errors.

3- In your model you need to add the 'fillable' fields.

Here's an example.

Add the model at the top of the controller:

    use App\Model;

Method to store :

    public function store(Request $request)
        $model= new Model();
        $model->category_id = $request->category_id;
        $model->name        =   $request->name;
        $model->description =   $request->description;
        $model->image       =   $request->image;
        $model->status      =   $request->status;
        $model->created_by  =   $request->created_by;
        return redirect('path/to/redirect/after/save')->with('success', 'Model added successfully);

or you can use:

    $model = new Model();

Also if you want the 'created_by' field filled automatically with the user id you need to remove the "required" on the top and add this:

    $model->created_by = Auth::id();

before the "save()" method, and of course include:

    use Auth;

In top of your controller.

In your model you need to have this:

    protected $fillable = [

And finally in your view for every input you need to add this after the element:

    @if ($errors->has('name'))
        <span class="invalid-feedback" role="alert">
            <strong>{{ $errors->first('name') }}</strong>

or you could add this after the "form" tag:

    @if ($errors->any())
        <div class="alert alert-secondary" role="alert">
            <div class="alert-icon">
                <i class="flaticon-warning "></i>
            <div class="alert-text">
                    @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
        </div><br />

TIP: if you want the user to keep the information they had in the form, the attribute value of the input should be like this:

    <input type="text" class="form-control" name="name" value="{{ old('name') }}">

I hope this helps. Regards. Daniel

Last updated 4 years ago.

sangrialdrete, manojibcarockers liked this reply


Thank you friends for your valuable solution .

I use input validation in **api side ** so This may be a reason of the issue.Because(i use front-end side angularjs)

I tried above solution but not solved. i don't know exact solution for this issue


I Got a solution with use of Manually Creating Validators

Solution : -



Code : -

        use Illuminate\Support\Facades\Validator;
        public function store(Request $request)
       $validator = Validator::make($request->all(), [
       if (!$validator->fails())
       $category = new Categories();
       return $category->category_id;
       return $validator->errors();

Finally thanks for all.(@ sangrialdrete,@ vstokesjr)

Last updated 4 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.