It is good to verify authentication in middleware. In my application, we use the same functions to check if the user sends the correct access_code to access the API methods. Even Laravel itself handles secure routes using Authenticate middleware.
The problem is that there is no silver bullet in how and where to store additional data.
One way is to save this in a user session.
Secondly, you need to use the Illuminate\Foundation\Application class. You can enter it in your __constructor() middleware and use it to save your data. Application class extends Container class that implements the ArrayAccess interface, which allows you to access its properties, such as an array. This allows you to not only get variables from the application, but also store them. Not the best way than the easiest.
public function __construct(\Illuminate\Foundation\Application $app) { $app['_foo'] = 'bar'; }
There are more of these hacks, but they are the simplest.
Maxim Lanin May 12, '15 at 10:03 2015-05-12 10:03
source share