get curent action name and controller name inlaravel
first call namespace
use Illuminate\Support\Facades\Route;
$curentaction = Route::getCurrentRoute()->getAction(); echo "<pre>"; print_r($curentaction); echo "</pre>";
output
Array ( [middleware] => Array ( [۰] => web [۱] => auth ) [uses] => App\Http\Controllers\ProfileController@getpaymentsettings [controller] => App\Http\Controllers\ProfileController@getpaymentsettings [namespace] => App\Http\Controllers [prefix] => /profile [where] => Array ( ) )
actionname only
$curentaction2 = Route::getCurrentRoute()->getActionMethod(); echo "<pre>"; print_r($curentaction2); echo "</pre>";
output
index
$currentAction = \Route::currentRouteAction(); echo "<pre>"; print_r($currentAction); echo "</pre>";
output
App\Http\Controllers\ProfileController@getpaymentsettings
list($controller, $method) = explode('@', $currentAction); $controller = preg_replace('/.*\\\/', '', $controller); echo "<pre>"; print_r($controller); echo "</pre>";
output
ProfileController