use auth middleware in laravel code example
Example 1: laravel get auth user id
// Get the currently authenticated user's ID...
$id = Auth::id();
Example 2: laravel set middleware default
If you want a middleware to run during every HTTP request to your application, list the middleware class in the $middleware property of your app/Http/Kernel.php class.