似乎无法成功地将变量传递到laravel路由

似乎无法成功地将变量传递到laravel路由,laravel,Laravel,我是一个完全的新手,试图自学laravel框架。我有一点PHP的经验,从过去的生活,我只是试图学习一个新的技能集。我不是一个开发商的贸易 我正在尝试完成一个关于路线的教程 在我的web.php文件中 Route::get('/test/{post}', function($post) { $posts = [ 'my-first-post' => 'Hello, this is my first blog post!', 'my-second-post' => 'N

我是一个完全的新手,试图自学laravel框架。我有一点PHP的经验,从过去的生活,我只是试图学习一个新的技能集。我不是一个开发商的贸易

我正在尝试完成一个关于路线的教程

在我的web.php文件中

Route::get('/test/{post}', function($post) {

$posts = [
    'my-first-post' => 'Hello, this is my first blog post!',
    'my-second-post' => 'Now I am getting the hang of this blogging thing',
    'test' => 'test'
];

if (! array_key_exists($post, $posts)) {
    abort(404, 'Sorry, that post was not found');
}

return view('post', [
    'post' => $posts[$post]
]);
});
<!DOCTYPE HTML>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>
        This is a test
    </title>

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">

</head>
<body>
    <div class="flex-center position-ref full-height">
        <div class="content">
            <div class="title m-b-md">
                this is a test
                {{$post}}
            </div>
        </div>
    </div>
</body>
</html>
在我的刀片文件里有这个

Route::get('/test/{post}', function($post) {

$posts = [
    'my-first-post' => 'Hello, this is my first blog post!',
    'my-second-post' => 'Now I am getting the hang of this blogging thing',
    'test' => 'test'
];

if (! array_key_exists($post, $posts)) {
    abort(404, 'Sorry, that post was not found');
}

return view('post', [
    'post' => $posts[$post]
]);
});
<!DOCTYPE HTML>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>
        This is a test
    </title>

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">

</head>
<body>
    <div class="flex-center position-ref full-height">
        <div class="content">
            <div class="title m-b-md">
                this is a test
                {{$post}}
            </div>
        </div>
    </div>
</body>
</html>

这是一个测试
这是一个测试
{{$post}
当我用以下URL刷新页面时

我得到以下错误

无效辩论例外 找不到查看[发布]


我在做傻事吗?

通过例外情况,似乎“post”视图不存在

请确保project_root/resources/views/post.blade.php中存在post.blade.php

有关更多详细信息,请参阅此链接:

谢谢!我想我知道我做错了什么。我使用test.blade.php来呈现页面。路由::get(/test/{post}引用了它,但没有返回视图('post')。感谢帮助:)