Laravel 5.4 - Array returning NULL instead of a numeric value -


here's problem bothering me while.

i have service provider pass data views, everytime sidebar rendered. this:

`          public function boot()    {     $userrole = array (db::table('users')->where('id','=', auth::id())->value('role'));    $menucase1 = [3,4,9,10];             $menucase2 = [1,2,3,10];     $menucase3 = [1,3,4,9,10];    $menucase4 = [4,9];     $commondata = compact('userrole','menucase1','menucase2','menucase3','menucase4');      view()->share('commondata', $commondata);     view::composer('sidebar', function ($view) {         $userrole = array (db::table('users')->where('id','=', auth::id())->value('role'));         $menucase1 = [3,4,9,10];         $menucase2 = [1,2,3,10];         $menucase3 = [1,3,4,9,10];          $menucase4 = [4,9];         $commondata = compact('userrole','menucase1','menucase2','menucase3','menucase4');     $view->with('commondata', $commondata);     });  }` 

doing {{ dd($commondata) }} returns correct values menucase arrays, null $userrole

if declare same $userrole variable in controller , call variable in view, received data correct.

why happening?

thanks in advance

can't understand trying do.

if want user role array, can using pluck method:

$userrole = user::where('id', auth::id())->pluck('role')->toarray(); 

but current user can role

$userrole = [auth::user()->role]; 

upd: can in view without sharing

{{ auth::user()->role }} 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -