Hello! I dig in Laravel 5.6. Here I am faced with the need to get parameters from routes. I know that they can be obtained by passing a parameter to the method that is called by this route.

The question is, how to get it in any other method? So far, in the open spaces of various forums I have not found the correct answer. Thank you in advance for all the answers!

    1 answer 1

    There is a class Illuminate \ Support \ Facades \ Route. Through it, you can get and assign any values ​​for the parameters of the route. Unfortunately, I did not find in the specifications that this class has a static current () method. And it is just needed to get the parameters of the route in the current URL.

    If it is useful to someone, here is the link to the specification for the Laravel Route class.

    The parameter can be obtained, for example, like this:

    Route::current()->parameter($name); Route::current()->parameters(); 

    You can assign it like this:

     Route::current()->setParameter($name, $value); 

    Check here like this:

     Route::current()->hasParameter($name);