Crud: Return with Validator errors

Created on 23 Jul 2016  路  15Comments  路  Source: Laravel-Backpack/CRUD

Now if we have an validator errors we just redirected back so better way its to show errors for user.

question

Most helpful comment

Hi @OSDDQD ,

This has happened to me before for custom CRUD entities, when I applied the web middleware in the routes.php file. Laravel 5.2+ applies the 'web' middleware automatically for normal request and if you apply it the second time, that happens.

I'm wondering - does removing the web middleware fix your problem?

All 15 comments

Hi @OSDDQD ,

The validation errors show up for me:
screen shot 2016-07-24 at 09 20 06

1) They don't for you?
2) What form were you using? (create or update)
3) What entity were you on? (Article, Category, Tag, MenuItem, etc)

Thanks!

Yes i found this code in view:
@if ($errors->any()) <div class="callout callout-danger"> <h4>{{ trans('backpack::crud.please_fix') }}</h4> <ul> @foreach($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif

  1. No
  2. Update form, dont try to reproduce errors with create form
  3. Custom entity with custom Request Form based on CrudRequest

I created a field with translations and it is necessary to validate nested field, for example: name.*
I look for the problem and give an answer.
Thanks.

I found some problems.
In Illuminate\Foundation\Http\FormRequest i get an validator errors but in form_content $errors is empty.
I will continue to look for the problem further, most likely I'll cause of this problem, because a lot has already modified the code.

Hi @OSDDQD ,

This has happened to me before for custom CRUD entities, when I applied the web middleware in the routes.php file. Laravel 5.2+ applies the 'web' middleware automatically for normal request and if you apply it the second time, that happens.

I'm wondering - does removing the web middleware fix your problem?

@tabacitu thanks!
It works for me.

This worked for me as well... thank you!

_removed 'web', from the following and errors came back:_

...
Route::group(['prefix' => 'admin', 'middleware' => ['web', 'auth'], 'namespace' => 'Admin'], function () {
...

any way to code a fix to CRUD package?

@BinaryBlock I don't there's anything to fix in the CRUD package. The error stems from each developer's route.php file.

Removing it from the CRUD will stop the panels from working, so... I think the pnly fix we can do is mention this in the documentation. Will do. Cheers!

Hi everyone! I'm not getting any errors, and I've already removed the web middleware. Any tip on how to get this working? I'll try to debug the errors variable to see where it gets lost.

I'm not getting any errors, and I've already removed the web middleware. Any tip on how to get this working?

@promatik What are the versions of software you're using? (backpack, laravel, etc)

@BinaryBlock Laravel is 5.4.28 and crud is the latest, updated today 3.2.13. I'm on windows, with xampp and PHP 7.1.4.

Hi Everyone, I found that Illuminate\Foundation\Exceptions\Handler.php > render() has the $errors on the $request. The exception is returned, now I don't know who should be listening to this.

Also, Illuminate\Foundation\Validation\ValidatesRequests.php > buildFailedValidationResponse() returns a redirect() which contains the errors (this came from Handler.php)

So I know the errors are being lost in the redirect. Because on Backpack\CRUD\app\Http\Controllers\CrudController.php > edit() there are no errors on the request or session.

Can someone help me with this?
Thanks.

@promatik - is this the same issue (that's closed)?

If so, could we reopen a new issue because I'm confused about whether it's open, not open, closed or such :(

@promatik - might it be that you have your routes defined in your web.php routes file, using the web middleware?

If so - that might be the issue. Laravel automatically places the routes defined in web.php under the web middleware. If you define it manually too, the web midleware is loaded twice, and things like flash session variables stop working.

@tabacitu yes, I'm using the web.php routes file, but I removed the 'web' from middleware array:

Route::group(['prefix' => 'admin', 'middleware' => ['auth'], 'namespace' => 'Admin'], function () {
    CRUD::resource('user', 'UserCrudController');
    ...
});

Should I move CRUD declarations to other route file? If so which one?

Guys! Sorry, I finally found what I was doing wrong.
I added a middleware to deal with user locale, and to do that I needed to start session first, so I added \Illuminate\Session\Middleware\StartSession::class on my $middleware (App\Http\kernel.php file).
The problem was the StartSession was repeated on web middleware. It was loading the start session twice.

Was this page helpful?
0 / 5 - 0 ratings