Get Laravel 5 controller name in view

后端 未结 4 1646
渐次进展
渐次进展 2020-12-03 14:02

Our old website CSS was set up so that the body tag had an id of the controller name and a class of the action name, using Zend Framework 1. Now we\'re switchi

4条回答
  •  抹茶落季
    2020-12-03 14:30

    To get something like PostController try following ...

    preg_match('/([a-z]*)@/i', $request->route()->getActionName(), $matches);
    $controllerName = $matches[1];
    

    $matches[1] includes the first group while $matches[0] includes everything matched. So also the @ which isn't desired.

提交回复
热议问题