Sure you can do a check if there is no value ,
create a custom middleware as such :-
<?php
namespace App\Http\Middleware;
use Closure;
class CheckUserSession
{
public function handle($request, Closure $next)
{
if (!$request->session()->exists('user')) {
// user value cannot be found in session
return redirect('/');
}
return $next($request);
}
}
then add this to Kernel.php located inside App\Http. This should go in the $routeMiddleware property array.
'usersession' => \App\Http\Middleware\CheckUserSession::class
finally apply it to your routes for example
Route::group(['middleware' => 'usersession'], function () {
Route::get('/', function () {
// Uses User Session Middleware
});
});
I suggest go through jeffrey's series on laravel it really will help you, thats how i learnt all of this!