How to check Auth in app service provider in laravel

In Laravel, if you want to check that a user is logged in or not at the time of application boot, you can use the following code where you can use Auth::guard('college')->check() to check if a user belongs to  guard('college') guard logged in or not.this can be done in appserviceprovider.php provider file under the providers folder.


public function boot(): void
{

view()->composer(['college.*'], function($view){
if(Auth::guard('college')->check())
{
$view->with('collegeProfile',collegeProfile::Where('userId', Auth::guard('college')->user()->id)->first());
}

});

}

Leave a Comment