jeudi 3 août 2017

Laravel 5.2 flash messages and errors suddenly not working

The last couple of days, I face a problem. Validation errors variable comes empty inside blade files.. I am developing a multilingual application in Laravel 5.2.45. So there are the validation error messages in each of them (resources/lang/{locale}/validation.php).

Validation rules live inside a Request file (e.g. ValidateUserRequest) containing the validation rules and declaring authorize as true. I then pass it to the controller. Bellow is my middlewares and part of my routes file.

Any help will be much appreciated

Kernel.php

 protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
    ],

    'api' => [
        'throttle:60,1',
    ],
 ];

 protected $routeMiddleware = [
    'auth_pabl' => \App\Http\Middleware\AuthenticateBackEnd::class,
    'auth' => \App\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
    'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
    'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
 ];

routes.php (all controllers inside Admin directory)

Route::auth();

Route::group ( [ 
    'namespace' => 'Admin'
], 
function () {

Route::get ( 'admin/dashboard', [ 

        'uses' => 'PanelController@dashboard',
        'as' => 'admin.dashboard'

] );

/*
 * Authors
 */

Route::get ( 'admin/authors', [ 

        'uses' => 'PanelController@authors',
        'as' => 'admin.authors'

] );

Route::post ( 'admin/authors', [ 

        'uses' => 'AuthorController@store',
        'as' => 'admin.authors.store' 
] );

Route::get ( 'admin/authors/{slug}/edit', [ 

        'uses' => 'AuthorController@edit',
        'as' => 'admin.authors.edit' 
] );

Route::post ( 'admin/authors/{username}/edit', [ 

        'uses' => 'AuthorController@update',
        'as' => 'admin.authors.update' 
] );

Route::get ( 'admin/authors/{username}/delete', [ 

        'uses' => 'AuthorController@delete',
        'as' => 'admin.authors.delete' 
] );

A session error would normally come from something like

    try{
        $event = Event::whereEnTitle($en_title)->firstOrFail();
    }catch (\Exception $e) {
        \Session::flash('errors', $e->getMessage());
        return redirect()->route('admin.events.create');

    }

And it is (not) displayed with

@if($errors->count()>0) <br /> <br />
<div id="#problem" class="alert alert-danger text-pull-left">
    <p>{!! trans('admin/form/placeholders.errors') !!}</p>
    <ul class="errors">
        @foreach($errors->all() as $error)
            <li></li>
        @endforeach
    </ul>
</div>
@endif

Finally php artisan route:list states that the "web" middleware is present (I have not declared it twice manually)



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2v3lfWM
via IFTTT

Aucun commentaire:

Enregistrer un commentaire