Laravel - adminlte.php无法识别Auth :: id()

时间:2017-09-17 20:29:12

标签: php laravel laravel-5

我已经下载并安装了adminlte包,为我创建了一个管理面板模板。该面板运行良好,我已经构建了很多功能,但我无法设法将变量发送到路由。例如:

在adminlte.php中,您可以构建如下的侧边菜单:

enter image description here

视图获得:

enter image description here

但是当我点击'Perfil'部分时,它无法识别Auth::id(),它会将其视为字符串而不是实际登录用户的ID。我得到的错误:

enter image description here

我尝试将use Illuminate\Support\Facades\Auth;添加到a​​dminlte.php和控制器,但仍无效。

路线:

// Middleware to check if user is Admin
  Route::group(['middleware' => 'Admin'], function() {

     Route::group(['prefix' => '/perfil'], function() {
        Route::get('/{id}', 'AdminPanelController@getProfile');
      });

   });

getProfile方法:

public function getProfile($id) {
    $user = User::findOrFail($id);
    return view("admin_panel.info_views.users.user_profile")->with("user", $user);
  }

adminlte.php:

<?php


return [

    /*
    |--------------------------------------------------------------------------
    | Title
    |--------------------------------------------------------------------------
    |
    | The default title of your admin panel, this goes into the title tag
    | of your page. You can override it per page with the title section.
    | You can optionally also specify a title prefix and/or postfix.
    |
    */

    'title' => 'AdminLTE 2',

    'title_prefix' => '',

    'title_postfix' => '',

    /*
    |--------------------------------------------------------------------------
    | Logo
    |--------------------------------------------------------------------------
    |
    | This logo is displayed at the upper left corner of your admin panel.
    | You can use basic HTML here if you want. The logo has also a mini
    | variant, used for the mini side bar. Make it 3 letters or so
    |
    */

    'logo' => '<b>UNIK</b>HB',

    'logo_mini' => '<b>U</b>NK',

    /*
    |--------------------------------------------------------------------------
    | Skin Color
    |--------------------------------------------------------------------------
    |
    | Choose a skin color for your admin panel. The available skin colors:
    | blue, black, purple, yellow, red, and green. Each skin also has a
    | ligth variant: blue-light, purple-light, purple-light, etc.
    |
    */

    'skin' => 'yellow',

    /*
    |--------------------------------------------------------------------------
    | Layout
    |--------------------------------------------------------------------------
    |
    | Choose a layout for your admin panel. The available layout options:
    | null, 'boxed', 'fixed', 'top-nav'. null is the default, top-nav
    | removes the sidebar and places your menu in the top navbar
    |
    */

    'layout' => null,

    /*
    |--------------------------------------------------------------------------
    | Collapse Sidebar
    |--------------------------------------------------------------------------
    |
    | Here we choose and option to be able to start with a collapsed side
    | bar. To adjust your sidebar layout simply set this  either true
    | this is compatible with layouts except top-nav layout option
    |
    */

    'collapse_sidebar' => false,

    /*
    |--------------------------------------------------------------------------
    | URLs
    |--------------------------------------------------------------------------
    |
    | Register here your dashboard, logout, login and register URLs. The
    | logout URL automatically sends a POST request in Laravel 5.3 or higher.
    | You can set the request to a GET or POST with logout_method.
    | Set register_url to null if you don't want a register link.
    |
    */

    'dashboard_url' => 'home',

    'logout_url' => 'logout',

    'logout_method' => null,

    'login_url' => 'login',

    'register_url' => 'register',

    /*
    |--------------------------------------------------------------------------
    | Menu Items
    |--------------------------------------------------------------------------
    |
    | Specify your menu items to display in the left sidebar. Each menu item
    | should have a text and and a URL. You can also specify an icon from
    | Font Awesome. A string instead of an array represents a header in sidebar
    | layout. The 'can' is a filter on Laravel's built in Gate functionality.
    |
    */

    'menu' => [
        'NAVEGAÇÃO PRINCIPAL',
        [
            'text' => 'Blog',
            'url'  => 'admin/blog',
            'can'  => 'manage-blog',
        ],
        [
            'text'        => 'Painel principal',
            'url'         => 'admin/painel',
            'icon'        => 'dashboard',
        ],
        [
            'text'    => 'Editar páginas',
            'icon'    => 'edit',
            'submenu' => [
                [
                    'text' => 'Vantagens',
                    'url'  => 'admin/editar_paginas/vantagens',
                    'icon_color' => 'purple',
                ],
                [
                    'text' => 'Dúvidas frequentes',
                    'url'  => "#",
                    'icon_color' => 'green',
                    'submenu' => [
                        [
                            'text' => 'Ver dúvidas/respostas',
                            'url'  => 'admin/editar_paginas/duvidas',
                            'icon_color' => 'green',
                        ],
                        [
                            'text' => 'Inserir dúvida/resposta',
                            'url'  => 'admin/editar_paginas/inserir_duvida',
                            'icon_color' => 'green',
                        ],
                    ],
                ],
                [
                    'text' => 'Equipe',
                    'url'  => "#",
                    'icon_color' => 'blue',
                    'submenu' => [
                        [
                            'text' => 'Ver equipe',
                            'url'  => 'admin/editar_paginas/equipe',
                            'icon_color' => 'blue',
                        ],
                        [
                            'text' => 'Inserir funcionário',
                            'url'  => 'admin/editar_paginas/inserir_funcionario',
                            'icon_color' => 'blue',
                        ],
                    ],
                ],
                [
                    'text'    => 'Tabela de Honorários',
                    'url'     => '#',
                    'icon_color' => 'orange',
                    'submenu' => [
                        [
                            'text' => 'Editar tabela',
                            'url'  => 'admin/editar_paginas/editar_tabela_honorarios',
                            'icon_color' => 'orange',
                        ],
                        [
                            'text' => 'Editar texto da tabela',
                            'url'  => 'admin/editar_paginas/editar_texto_tabela_honorarios',
                            'icon_color' => 'orange',
                        ],
                        [
                            'text' => 'Inserir honorários',
                            'url'  => 'admin/editar_paginas/inserir_honorario',
                            'icon_color' => 'orange',
                        ],
                    ],
                ],
                [
                    'text' => 'Level One',
                    'url'  => '#',
                ],
            ],
        ],
        'CONFIGURAÇÕES DA CONTA',
        [
            'text' => 'Perfil',
            'url' => 'admin/perfil'.\Auth::user()->id,
            'icon' => 'user',
        ],
        [
            'text' => 'Alterar senha',
            'url'  => 'admin/settings',
            'icon' => 'lock',
        ],
        'LABELS',
        [
            'text'       => 'Important',
            'icon_color' => 'red',
        ],
        [
            'text'       => 'Warning',
            'icon_color' => 'yellow',
        ],
        [
            'text'       => 'Information',
            'icon_color' => 'aqua',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Menu Filters
    |--------------------------------------------------------------------------
    |
    | Choose what filters you want to include for rendering the menu.
    | You can add your own filters to this array after you've created them.
    | You can comment out the GateFilter if you don't want to use Laravel's
    | built in Gate functionality
    |
    */

    'filters' => [
        JeroenNoten\LaravelAdminLte\Menu\Filters\HrefFilter::class,
        JeroenNoten\LaravelAdminLte\Menu\Filters\ActiveFilter::class,
        JeroenNoten\LaravelAdminLte\Menu\Filters\SubmenuFilter::class,
        JeroenNoten\LaravelAdminLte\Menu\Filters\ClassesFilter::class,
        JeroenNoten\LaravelAdminLte\Menu\Filters\GateFilter::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Plugins Initialization
    |--------------------------------------------------------------------------
    |
    | Choose which JavaScript plugins should be included. At this moment,
    | only DataTables is supported as a plugin. Set the value to true
    | to include the JavaScript file from a CDN via a script tag.
    |
    */

    'plugins' => [
        'datatables' => true,
    ],
];

2 个答案:

答案 0 :(得分:1)

解决方案不是传递id trough URL,而是更改控制器方法。

自:

public function getProfile($id) { $user = User::findOrFail($id); return view("admin_panel.info_views.users.user_profile")->with("user", $user); }

致:

public function getProfile() { $user = Auth::user(); return view("admin_panel.info_views.users.user_profile")->with("user", $user); }

还将路线更改为不接收参数。通过这种方式,我设法访问用户信息,而无需传递他们的ID,这是我遇到麻烦的地方。

答案 1 :(得分:0)

因为它在引号内。将其更改为:

'url' => 'admin/perfil'.\Auth::user()->id