<bdo id='9bqWj'></bdo><ul id='9bqWj'></ul>

      <legend id='9bqWj'><style id='9bqWj'><dir id='9bqWj'><q id='9bqWj'></q></dir></style></legend>

      <small id='9bqWj'></small><noframes id='9bqWj'>

    1. <i id='9bqWj'><tr id='9bqWj'><dt id='9bqWj'><q id='9bqWj'><span id='9bqWj'><b id='9bqWj'><form id='9bqWj'><ins id='9bqWj'></ins><ul id='9bqWj'></ul><sub id='9bqWj'></sub></form><legend id='9bqWj'></legend><bdo id='9bqWj'><pre id='9bqWj'><center id='9bqWj'></center></pre></bdo></b><th id='9bqWj'></th></span></q></dt></tr></i><div id='9bqWj'><tfoot id='9bqWj'></tfoot><dl id='9bqWj'><fieldset id='9bqWj'></fieldset></dl></div>

      <tfoot id='9bqWj'></tfoot>
    2. laravel 路由过滤器检查用户角色

      时间:2023-10-31
        <tbody id='fGvbM'></tbody>
        <bdo id='fGvbM'></bdo><ul id='fGvbM'></ul>
        <tfoot id='fGvbM'></tfoot>
              1. <small id='fGvbM'></small><noframes id='fGvbM'>

                <i id='fGvbM'><tr id='fGvbM'><dt id='fGvbM'><q id='fGvbM'><span id='fGvbM'><b id='fGvbM'><form id='fGvbM'><ins id='fGvbM'></ins><ul id='fGvbM'></ul><sub id='fGvbM'></sub></form><legend id='fGvbM'></legend><bdo id='fGvbM'><pre id='fGvbM'><center id='fGvbM'></center></pre></bdo></b><th id='fGvbM'></th></span></q></dt></tr></i><div id='fGvbM'><tfoot id='fGvbM'></tfoot><dl id='fGvbM'><fieldset id='fGvbM'></fieldset></dl></div>
                <legend id='fGvbM'><style id='fGvbM'><dir id='fGvbM'><q id='fGvbM'></q></dir></style></legend>

                本文介绍了laravel 路由过滤器检查用户角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在 laravel 4 中构建一个 restful api,其中有具有不同类型权限的用户.我想根据用户角色(保存在数据库的用户表中)限制对不同路由的访问

                I am building a restful api in laravel 4 where there are users with different types of permission. I want to restrict access to different routes depending on the user role (which is saved in the user table in db)

                我该怎么做?这是我到目前为止所拥有的(到目前为止还没有工作).

                How would I do that? Here is what I have so far (it's not working so far).

                filters.php

                filters.php

                //allows backend api access depending on the user's role once they are logged in
                Route::filter('role', function()
                { 
                return Auth::user()->role;
                }); 
                

                routes.php

                 Route::group(array('before' => 'role'), function($role) {
                 if($role==1){
                        Route::get('customer/retrieve/{id}', 'CustomerController@retrieve_single');
                        Route::post('customer/create', 'CustomerController@create');
                        Route::put('customer/update/{id}', 'CustomerController@update');
                 }
                
                    });
                

                是否有可能我为组过滤器"编写了错误的语法?

                Is it possible that I'm writing the syntax wrong for a "group filter"?

                推荐答案

                尝试以下操作:

                filters.php

                Route::filter('role', function()
                { 
                  if ( Auth::user()->role !==1) {
                     // do something
                     return Redirect::to('/'); 
                   }
                }); 
                

                routes.php

                 Route::group(array('before' => 'role'), function() {
                        Route::get('customer/retrieve/{id}', 'CustomerController@retrieve_single');
                        Route::post('customer/create', 'CustomerController@create');
                        Route::put('customer/update/{id}', 'CustomerController@update');
                
                
                });
                

                这篇关于laravel 路由过滤器检查用户角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Laravel 4 中访问包控制器 下一篇:Laravel 4.2:将 PHP 文件(库)包含到控制器中

                相关文章

                <i id='fEYzH'><tr id='fEYzH'><dt id='fEYzH'><q id='fEYzH'><span id='fEYzH'><b id='fEYzH'><form id='fEYzH'><ins id='fEYzH'></ins><ul id='fEYzH'></ul><sub id='fEYzH'></sub></form><legend id='fEYzH'></legend><bdo id='fEYzH'><pre id='fEYzH'><center id='fEYzH'></center></pre></bdo></b><th id='fEYzH'></th></span></q></dt></tr></i><div id='fEYzH'><tfoot id='fEYzH'></tfoot><dl id='fEYzH'><fieldset id='fEYzH'></fieldset></dl></div>
              2. <tfoot id='fEYzH'></tfoot>
                <legend id='fEYzH'><style id='fEYzH'><dir id='fEYzH'><q id='fEYzH'></q></dir></style></legend>
                • <bdo id='fEYzH'></bdo><ul id='fEYzH'></ul>

                  <small id='fEYzH'></small><noframes id='fEYzH'>