ozimos/LMS_Music

View on GitHub
app/Http/Middleware/AddUserId.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App\Http\Middleware;

use Closure;

class AddUserId
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = $request->user();
        $userId = $user ? ['user_id' => $user->id] : [];
        $request->merge($userId);

        return $next($request);
    }
}