M
M
mrSeller2018-03-20 10:53:31
Laravel
mrSeller, 2018-03-20 10:53:31

Is it possible to create a controller that will run with any route?

You need to run code that, if the user is not authorized, creates a session with a selection from the database.
I thought that it would be convenient to do this in a "general" controller, since sessions cannot be used in AppServiceProvider.
I did it through the facade, but spreading the same code into two dozen controllers - thank you.
And if something changes, then deleting this code is some kind of hell.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-03-20
@mrSeller

You need to run code that, if the user is not authorized, creates a session with a selection from the database.

shta?
shta?
controllers that are executed with any/required route are called middleware.
And everything described is some kind of solution through the ass, to put it mildly.
What sessions are needed in the AppServiceProvider, why the hell, you don’t need to touch anything at all, connect a couple of observers, or register some kind of package.
Study the framework and its capabilities, because you are obviously coming from the wrong side. And think over the task normally, a session with a selection from the database is a normal authorization. What are you trying to stir up there and if out of the box it all works through php artisan make:auth.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question