Reputation: 392
I've downloaded and installed adminlte package to create a admin panel template for me. The panel is working well, I've already built a lot of functionalities but i can't manage to send a variable to a route. Example:
In adminlte.php you build the side-menu like:
The view gets:
But when i click in the 'Perfil' section it doesn't recognize the Auth::id()
, it treats it as a String instead of the actual logged user's id. The error I get:
I tried adding use Illuminate\Support\Facades\Auth;
to both adminlte.php and controller but still doesn't work.
Route:
// Middleware to check if user is Admin
Route::group(['middleware' => 'Admin'], function() {
Route::group(['prefix' => '/perfil'], function() {
Route::get('/{id}', 'AdminPanelController@getProfile');
});
});
getProfile method:
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,
],
];
Upvotes: 1
Views: 2750
Reputation: 392
The solution was not to pass the id trough URL but change the controller method.
From:
public function getProfile($id) {
$user = User::findOrFail($id);
return view("admin_panel.info_views.users.user_profile")->with("user", $user);
}
To:
public function getProfile() {
$user = Auth::user();
return view("admin_panel.info_views.users.user_profile")->with("user", $user);
}
Also changed the route to not receive a parameter. This way i managed to access user info without needing to pass their id trough URL which is where i had been having trouble.
Upvotes: 1
Reputation: 570
Because it is within the quotes. Change it to:
'url' => 'admin/perfil'.\Auth::user()->id
Upvotes: 0