A
A
Alexander Ablizin2016-08-26 16:55:25
Python
Alexander Ablizin, 2016-08-26 16:55:25

Is it possible to pass a variable from a method to an intermediary (middleware)?

All health! Please help me understand.
For example, I have a FooController controller with a myMethod method, and myMiddleware middleware
The route says:
Route::post('/slug','[email protected]');
The controller says:

#...
class FooController extends Controller
{
    public function __construct()
    {
        $this->middleware('myMiddleware', ['only' => ['myMethod']]);
    }
    public function myMethod(Request $request)
    {
        #...
    }
    #...
}

In this case, the intermediary works with the Request data that comes from the route, checks something, checks, etc. And only then, if everything is OK, the method executes. Is it possible to pass data directly from the body of the method to the intermediary? Or it contradicts the very meaning of the intermediary and it is necessary to inject dependencies, etc.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Severus256, 2016-06-10
@severus256

You probably have a problem with the encoding in the excel file.

A
Alexander Mamaev, 2016-06-10
@virtual_universe

there is a character in the file that cannot be displayed in ASKII

V
Vlad Tokarev, 2016-08-26
@mcmraak

This contradicts the meaning of the mediator, because the meaning in it is to call the method after checking if everything is OK or throw an error if not.
If you want to call a check from a method, then you should just use some kind of helper class, and not specifically middleware.

L
litvinenkow, 2020-02-07
@litvinenkow

a question arose, since middleware is being discussed here, is
it possible to call the midlleware handle method directly from the controller and how to do it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question