当我使用Auth时,我的服务提供商收到错误'试图获取非对象的属性':
public function boot()
{
$roles = DB::table('folders')->orderBy('folder_id', 'desc')->where('level', 0)->get();
if(Auth::user()->level == 1){
$roles1 = DB::table('folders')->orderBy('folder_id', 'asc')->where('level', 1)->get();
}else{
$user = DB::table('folder_permissions')->where('user_id', Auth::user()->id)->get();
foreach($user as $u){
$roles1 = DB::table('folders')->orderBy('folder_id', 'asc')->where('level', 1)->get();
}
}
$treeFolder = DB::table('folders')->where('level', 0)->get();
if(!empty($treeFolder)){
foreach($treeFolder as $folders){
$arrayCategories[$folders->folder_id] = array("parent_id" => $folders->parent, "name" => array("fname" => $folders->folder_name, "id" => $folders->folder_id));
}
}else{
$arrayCategories = FALSE;
}
view()->share(['folder' => $roles, 'prime_folders' => $roles1, 'treeView' => $arrayCategories]);
}
我已经打电话给'使用Illuminate \ Support \ Facades \ Auth;',但没有任何事情发生。
有人能帮助我吗?
答案 0 :(得分:0)
view()->composer('*', function ($view)
{
$roles = DB::table('folders')->orderBy('folder_id', 'desc')->where('level', 0)->get();
if(Auth::user()->level == 1){
$roles1 = DB::table('folders')->orderBy('folder_id', 'asc')->where('level', 1)->get();
}else{
$user = DB::table('folder_permissions')->where('user_id', Auth::user()->id)->get();
foreach($user as $u){
$roles1 = DB::table('folders')->orderBy('folder_id', 'asc')->where('level', 1)->get();
}
}
$treeFolder = DB::table('folders')->where('level', 0)->get();
if(!empty($treeFolder)){
foreach($treeFolder as $folders){
$arrayCategories[$folders->folder_id] = array("parent_id" => $folders->parent, "name" => array("fname" => $folders->folder_name, "id" => $folders->folder_id));
}
}else{
$arrayCategories = FALSE;
}
//if this line doesn't work then.... see below line after this coming up line
$view->share(['folder' => $roles, 'prime_folders' => $roles1, 'treeView' => $arrayCategories]);
$view->with('folder', $roles)->with('prime_folders',$roles1)->with('treeView',$arrayCategories);
});