E
E
Evgeny Romashkan2018-07-16 18:32:18
Laravel
Evgeny Romashkan, 2018-07-16 18:32:18

Laravel routes, what's the syntax for (uses ..., as ...)?

https://github.com/developerdino/example-articles-...

Route::get(
    'articles/{article}/relationships/author',
    [
        'uses' => \App\Http\Controllers\ArticleRelationshipController::class . '@author',
        'as'   => 'articles.relationships.author',
    ]
);

What does the array passed as the second argument mean, where can I read about it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2018-07-16
@EvgeniiR

uses is a callback, that is, what will be executed when your path pattern matches the path in the browser, translated as "use", in the example the controller method is used
as -- the name of the route, so that later it can be accessed from view for example and get the path
judging by this piece - there are a lot of routes and they are connected by common sections, so you can combine them into groups and namespaces and thereby improve the readability of the code!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question