I'm using Laravel with the AdminLTE layout
I made this function in the file config/adminlte.php
to try to define when the menu appears in the sidebar:
<?php
use Illuminate\Support\Facades\Auth;
function teste()
{
$personal = User::find(Auth::user()->id);
if($personal->nivel == 1) return true;
else return false;
}
if(teste()){
$painel = 'PAINEL ADMINISTRATIVO';
$menu = [
'text' => 'Usuários Cadastrados',
'url' => 'users',
'icon' => 'users',
];
$menu2 = [
'text' => 'Cadastrar Novo Usuário',
'url' => 'users/create',
'icon' => 'user-plus',
];
}else{
$painel = '';
$menu = '';
$menu2 = '';
}
But this is returning this error:
Fatal error: Uncaught ReflectionException: Class view does not exist in D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Container\Container.php:752 Stack trace: #0
D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Container\Container.php(752): ReflectionClass->__construct('view') #1
D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Container\Container.php(631): Illuminate\Container\Container->build('view') #2
D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Container\Container.php(586): Illuminate\Container\Container->resolve('view', Array) #3
D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(732): Illuminate\Container\Container->make('view', Array) #4
D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(110): Illuminate\Foundation\Application->make('view', Array) #5
D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(965): app('Illuminate\C in D:\wamp64\www\sisFarmacia\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 752
If you change if(teste())
by if(1)
the system runs right by displaying the menu, if(0)
and does not display the menu
By the tests I did, I believe the problem is in Auth::user()->id
but I do not understand why