samedi 2 juillet 2016

Middleware on laravel 5.2 redirecting without reason

I am actually making a laravel app starting with rappasoft boilerplate Github Link to Rappasoft

I changed the AdminLte Theme for the Neon Admin theme and i started making a posts addition to the code.

I still use the Routing method that Rappasoft used and the same middleware, I just added some permissions and of course some controllers and routes.

Here is the routes file:

    Route::group(['middleware' => 'web'], function() {
        /**
         * Switch between the included languages
         */
        Route::group(['namespace' => 'Language'], function () {
            require (__DIR__ . '/Routes/Language/Language.php');
        });

        /**
         * Frontend Routes
         * Namespaces indicate folder structure
         */
        Route::group(['namespace' => 'Frontend'], function () {
            require (__DIR__ . '/Routes/Frontend/Frontend.php');
            require (__DIR__ . '/Routes/Frontend/Access.php');
        });
    });

    /**
     * Backend Routes
     * Namespaces indicate folder structure
     * Admin middleware groups web, auth, and routeNeedsPermission
     */
    Route::group(['namespace' => 'Backend', 'prefix' => 'admin', 'middleware' => 'admin'], function () {
        /**
         * These routes need view-backend permission
         * (good if you want to allow more than one group in the backend,
         * then limit the backend features by different roles or permissions)
         *
         * Note: Administrator has all permissions so you do not have to specify the administrator role everywhere.
         */
        require (__DIR__ . '/Routes/Backend/Dashboard.php');
        require (__DIR__ . '/Routes/Backend/Access.php');
        require (__DIR__ . '/Routes/Backend/LogViewer.php');
        require (__DIR__ . '/Routes/Backend/post.php');



    });

And the Posts.php that its required:

    Route::group([
        'prefix'     => 'post',
        'namespace'  => 'Post',
        'middleware' => 'access.routeNeedsPermission:view-access-management',
        'middleware' => 'access.routeNeedsPermission:view-post-panel',
    ], function() {

        Route::get('/', 'postController@index')->name('indexPost');
        Route::get('/new', 'postController@create')->name('CreatePost');

    });

The Route it's

And when i submit http://ift.tt/29b73j5

When i submit the page redirects me automatically to the home link.

It's not even getting to the controller i made a dd('Hello World'); to see if it was getting to the Store() function in the controller and it's not.

Making some modifications in the code i made a function to the same route on the Routes.php

    Route::group([

        'prefix' => 'admin',
        'namespace' => 'Backend',

    ],function(){

        Route::group([

            'prefix' => 'post',
            'namespace' => 'Post',

        ],function(){
            Route::post('store', 'postController@store')->name('StorePost');

        });


    });

it works, it goes to the controller and gives me the dd('Hello Wolrd') but i dont have permission filters if i add the:

    'middleware' => 'access.routeNeedsPermission:view-access-management',
    'middleware' => 'access.routeNeedsPermission:view-post-panel',
    'middleware' => 'access.routeNeedsPermission:view-post-panel',

it doesn't work, and i verified that the user has the needed permissions so i really dont know, please help.

If you need anything else just let me know please.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire