Laravel9-无法打开流:没有此类文件或目录

发布于 2025-02-07 05:20:40 字数 561 浏览 1 评论 0原文

可以为此提供一些帮助。

我的Web.php文件具有以下代码:

Route::get('/', function() {
    return view('posts');
});

Route::get('posts/{post}', function ($slug) {
    $post = file_get_contents(__DIR__ . "/../resources/posts/{slug}.html");
    return view('post' , [
        'post' => $post
    ]);
});

当我尝试运行代码时 - 我会收到以下错误:

file_get_contents(/用户/用户名/sites/blog/doutes /../资源/posts/{slug} .html):无法打开流:没有这样的文件或目录

任何想法?为了避免疑问 - 在发布此消息之前,我已经审查了在线问题,并且仍然存在相同的问题。

Could do with some help on this one.

My web.php file has the following code:

Route::get('/', function() {
    return view('posts');
});

Route::get('posts/{post}', function ($slug) {
    $post = file_get_contents(__DIR__ . "/../resources/posts/{slug}.html");
    return view('post' , [
        'post' => $post
    ]);
});

When I try to run the code - I get the following error:

file_get_contents(/Users/username/Sites/blog/routes/../resources/posts/{slug}.html): Failed to open stream: No such file or directory

Any ideas? For the avoidance of doubt - I have reviewed online issues prior to posting this message and still have the same issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚我心虐我身 2025-02-14 05:20:40

您缺少一个$,应该是

$post = file_get_contents(__DIR__ . "/../resources/posts/$slug.html");

You are missing a single $, it should be

$post = file_get_contents(__DIR__ . "/../resources/posts/$slug.html");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文