i passed variable to all views in AppServiceProvider boot() i stored in this variable the name of the first user in the database so i can put it in my layout as title
the problem happenes when there is no user in the database (new databases) it through exception which says $title is not defind and that is true it is not defind so i tried to make if statment but it ignore it for some reason
boot ()
public function boot()
{
Schema::defaultStringLength(191);
View::composer('*',function($view){
$title = DB::table('users')->first();
$view->with('title',$title);
});
i tried this as the logic but didn't work
public function boot()
{
Schema::defaultStringLength(191);
$check = DB::table('users')->first();
if ($check != null) {
View::composer('*',function($view){
$title = DB::table('users')->first();
$view->with('title',$title); });
}else {
return view('nouser');
}
there is no syntax error but i think the problem is every time the website reloads it renders all the layouts ( i have 3) guest and admin have
<title>{{$title->name}}</title>
and app which the title is not dynamic in it and the nouser page i coded i extended the app layout bcs it doesn't have this variable which is undefined
the problem is i need to hide this exception from the user and redirect him to page that says please register and then i redirect him to the main pages after regiestration