How to create metadata (custom data) on an Laravel route?

Asked

Viewed 111 times

3

I wonder if in Laravel, beyond the information I already have on a route, as the name, action or uri, there is some way to define metadata.

For example:

Route::get('/', [
  'uses'      => 'HomeController@getIndex',
  'as'        => 'home',
  '__title__' => 'Página inicial'
]);

In Laravel, there are some have been to recover that value of __title__ which I defined on that route?

1 answer

1


There is, you can capture using $request->route()->getAction()['__title__'].

For example

class HomeController 
{
    public getIndex(Request $request) {
        $title = $request->route()->getAction()['__title__'];

        return view('sua_view', [
          'title' => $title,
          'dados' => $model
        ]);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.