A
A
Alexander2017-10-09 10:26:36
Laravel
Alexander, 2017-10-09 10:26:36

How to call the controller from the route function?

Route::get('{url_1}/{url_2?}/{url_3?}', function ($url_1, $url_2 = null, $url_3 = null) {
    //Действия, как тут при нужно условии вызвать нужный контроллер?
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Perin, 2017-10-09
@seoperin

Route::get('{url_1}/{url_2?}/{url_3?}', ['uses' => '[email protected]']);

// Your controller
public function method ($url_1, $url_2 = null, $url_3 = null) {
    //Действия
}

More or less like this

K
Konstantin B., 2017-10-09
@Kostik_1993

If you use a closure function, then it is already your controller. If you have some actions in some controller and you want to use the same actions in routes, then this already turns out to be business logic and you need to put it in a separate class. What you're trying to do is wrong

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question