Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel-根据文件的完整路径获取视图名称_Laravel_View - Fatal编程技术网

Laravel-根据文件的完整路径获取视图名称

Laravel-根据文件的完整路径获取视图名称,laravel,view,Laravel,View,我想知道是否可以根据视图文件的完整路径获得视图名称 代码示例(期望代码): 我能做到这一点吗 谢谢我刚得到一个解决方案 function get_view_name($full_path){ $view_root_path = config('view.paths')[0]; $view_name = strtr($full_path, [ $view_root_path.'/' => '', '.blade.php' => '',

我想知道是否可以根据视图文件的
完整路径获得
视图名称

代码示例(期望代码):

我能做到这一点吗

谢谢

我刚得到一个解决方案

function get_view_name($full_path){
    $view_root_path = config('view.paths')[0];

    $view_name = strtr($full_path, [
        $view_root_path.'/' => '',
        '.blade.php' => '',
        '/' => '.',
    ]);

    return $view_name;
}
但我认为这是一个相当肮脏的解决方案

function get_view_name($full_path){
    $view_root_path = config('view.paths')[0];

    $view_name = strtr($full_path, [
        $view_root_path.'/' => '',
        '.blade.php' => '',
        '/' => '.',
    ]);

    return $view_name;
}
所以,我仍然希望其他人能得到更好、更干净的解决方案

function get_view_name($full_path){
    $view_root_path = config('view.paths')[0];

    $view_name = strtr($full_path, [
        $view_root_path.'/' => '',
        '.blade.php' => '',
        '/' => '.',
    ]);

    return $view_name;
}

谢谢。

您可以使用此按钮获取路线名称

$request->route()->getName();
或者,如果您没有$request,而您需要路由名称,您可以使用request类来实现这一点

use Illuminate\Http\Request

Request::route()->getName();

对不起,兄弟…我的问题是“获取视图名称”,而不是“获取路由名称”。。。顺便说一下,谢谢你的帮助。。。