Skip to content

Instantly share code, notes, and snippets.

Last active October 1, 2022 19:27
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Merging the current user ID to the request in Laravel using web middleware
namespace App\Http\Middleware;
use Closure;
class MergeUserIdIntoRequest
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
public function handle($request, Closure $next)
$request->merge(['user_id' => auth()->id()]);
return $next($request);
Copy link

Able to always get the authenticated user ID by $request->user_id .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment