Error while trying to use function return in if

Asked

Viewed 39 times

0

I’m using the Laravel with the layout Adminlte

I did this function in the file config/adminlte.php to try to define when the sidebar menu appears:

<?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 error is returning to me:

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

Should the if(teste()) for if(1) the right wheel system displaying the menu, if(0) and does not display the menu

From the tests I’ve done, I believe the problem lies in Auth::user()->id but I don’t understand why

  • I saw some questions regarding the error and many cite that values in the file . env cannot contain spaces. Have you tried to verify this?

  • The system works perfectly if in place of if(test()) I put if(1), that’s where the error appears

  • @I edited to explain better the situation

  • See if you have Illuminate View Viewserviceprovider listed in providers in the config/app.php file.

  • You have this other answer here: https://stackoverflow.com/a/34591724/1377664

  • @The problem is in the call of the Auth::user()->id, just remove it that works ok, put it returns the error, and tested using other logic where this is called at different positions in the code and the same error

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.