php – How to create metadata (custom data) in a Laravel route?

Question:

I would like to know if in Laravel, in addition to the information I already have in a route, such 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, is there any way to retrieve this __title__ value that I set on this route?

Answer:

There is, you can capture it 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
        ]);
    }
}
Scroll to Top
AllEscort