Learn how to get the current user (or other session data) in a Laravel controller constructor
Joseph Silber shows us how to get the current user in a Laravel controller constructor.
Let's discuss something many people have accidentally discovered: you cannot use session data directly in a controller's constructor.
This change was introduced in Laravel 5.3, when the middleware pipeline was rewired to make global scopes work with session data.
In this post we'll examine the problem in more detail, and look at various ways to solve it.
This post is submitted by one of our members. You may submit a new post here.