A
A
Anton Anton2018-08-21 20:22:35
Laravel
Anton Anton, 2018-08-21 20:22:35

How to pass a parameter from $_POST to the controller?

There is a controller that accepts a parameter in this way: I want to make it accept a parameter via post, it turned out like this:
Route::get('/path/{token}', '[email protected]');

Route::post('/path', function () {
    return (new Controller)->verify($_POST['token']);
});

But the feeling that this is somewhat wrong does not leave. How will be correct?
It is undesirable to rewrite the controller itself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anlamas, 2018-08-21
@Fragster

What???? Would you like to rewrite?

Route::post('path', '[email protected]');
// вот это
public fuction verify($token){}
// нежелательно переписать в это?
public fuction verify(Request $request)
{
     $token = $request->token;
}

J
JhaoDa, 2018-08-21
@JhaoDa

Have you tried reading the documentation?
For example, https://laravel.com/docs/5.6/middleware but it's still a crutch, because the only right solution is to rewrite the controller.
You, if anything, just hint - I'll call the police, because you seem to be threatened and forbidden to change the controller. I don't see any other reason.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question