How to detect current resource route in laravel?

Member

by larissa , in category: PHP Frameworks , 10 months ago

How to detect current resource route in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 10 months ago

@larissa 

In Laravel, you can detect the current resource route by using the Route::currentRouteName() method. This method will return the name of the current route if it has been named in your routes file.


For example, if you have a resource route defined like this:

1
Route::resource('posts', 'PostController');


And you want to detect the current route in your controller or view, you can do so by using Route::currentRouteName() like this:

1
$currentRoute = Route::currentRouteName();


You can then use this $currentRoute variable to determine the current route and perform any necessary actions based on it.

Related Threads:

How to get the current route name in Laravel?
How to define route name for nested resource in ember.js?
How to reload current route in ember.js?
How to get the current route name in vue.js?
How to detect if a field has input in laravel?
How to check current user in laravel?