Skip to content

An Open Letter to the Core Laravel Developer Team [5.3 upgrade breaks Auth::user() in the base controller] #15072

Closed
@sstringer

Description

@sstringer

With Laravel 5.3, an undocumented breaking change was introduced where middleware are initialized after the controller class is constructed. This means app-critical middleware like Auth--specifically Auth::user()--are not available to the controller's __construct() method.

With the deepest respect to the Laravel team, I ask that you please reconsider this decision in light of the fact that this change appears to have adversely affected many developers with legacy 5.2 apps.

Surely there is a compromise solution here. Perhaps you could create a backwards-compatibility flag that lets me trigger the base controller's construction after the middleware has been initialized, you will allow legacy apps to be upgraded to 5.3 with ease. The default could be what you have now in 5.3 so fresh apps can be built the "new," faster way. This would go a long way towards making your app developers happy.

I've been taught my whole object-oriented coding career that efficient code is written once and used often. I've also been taught that, when employing MVC architecture, logic goes in the Controller class, never in the View. If it's common logic to more than one method, it goes in the parent class, and if it's common logic that is called every time the class is instantiated, it goes in (or is triggered by) the __construct() method. With that in mind, I would argue that allowing access to the Auth::user() object in the base controller's __construct() method is not only desirable but the most efficient methodology here. It's written once, easily tested, called automatically every time, and is available to the entire app.

Regardless of whether you take issue with this approach, the reality is that many Laravel apps have been built around the ability to access Auth::user() from the base controller's __constructor() and 5.3 breaks these apps.

On behalf of those affected, my open request is that you provide a compromise solution quickly with a point upgrade. A flag that lets us optionally turn on a backwards-compatibility mode that processes middleware before the base class is constructed would allow those of us who did it the "old" way to upgrade with ease, while those who are building new apps on 5.3 can do it the "new" way by default. Perhaps there is a better way to help those of us stuck at 5.2, but please don't underestimate the amount of pain this upgrade has caused.

Many thanks for your time and consideration on this matter.

Regards,
Steve Stringer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions