mardi 26 septembre 2017

How to inspect the current Named Route using Laravel 5.2

according to the Laravel 5.5 docs, there is a named() method for accessing route names:

if ($request->route()->named('profile')) {
    //
}

Inspecting the source, I learned that this named method simply fetches the 'as' property of the action object:

$this->action['as'] 

My problem is I'm stuck using Laravel 5.2, which doesn't have a named() method. I can't use route()->action['as'] in my blade template, because the actionobject is protected. Is there an equivalent getter method in 5.2, to check the name of the current route? I want to flow control in my blade.php file like this:

@if(route()->action['as'] == 'blog.edit')
    //
@endif

Maybe I missed it, but I didn't see anything in the Laravel 5.2 docs: http://ift.tt/2xDOCSx

I succeeded in checking the route using

@if(request()->is('blog/add'))
    //
@endif

But that is using the route URI. I prefer to use the route name instead as it's less clunky



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fOlhLN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire