简体   繁体   English

Laravel 9 + Jetstream 中的自定义视图不会在没有先测试的情况下加载

[英]Custom views in Laravel 9 + Jetstream won't load without testing first

I have a new project I created recently using the latest Laravel 9 and Jetstream with Livewire.我最近使用最新的 Laravel 9 和带有 Livewire 的 Jetstream 创建了一个新项目。 I've created some migrations and seeders and they run perfectly with Artisan.我创建了一些迁移和播种器,它们与 Artisan 完美运行。

Now I'm ready to start creating my homepage.现在我准备开始创建我的主页。 I create a brand-new file called index.blade.php in the resources/views directory.我在resources/views目录中创建了一个名为index.blade.php的全新文件。 I give it the contents of "Hello World."我给它的内容是“Hello World”。 That's it.而已。 No boilerplate, no HTML, nothing.没有样板,没有 HTML,什么都没有。 I update the main "/" route to point to "index" instead of "welcome".我将主“/”路由更新为指向“index”而不是“welcome”。 I then create a Feature Test to make sure that getting the "/" route returns a status code of 200. It runs great.然后我创建了一个功能测试,以确保获取“/”路由返回状态代码 200。它运行良好。 The page also loads fine in a browser displaying the "Hello World" text.该页面还可以在显示“Hello World”文本的浏览器中正常加载。

Now comes the part where I get confused.现在是我感到困惑的部分。 I change the "Hello World" text to just say "Hello".我将“Hello World”文本更改为只说“Hello”。 Refreshing the browser, I get the following message:刷新浏览器,我收到以下消息:

没有权限?

If I run the same Feature Test again, it still passes fine.如果我再次运行相同的功能测试,它仍然可以通过。 Then, when I refresh the browser again after having run the test, it loads!然后,当我在运行测试再次刷新浏览器时,它会加载!

I have tried out many different procedures, but it seems like the page simply will not load whenever I make any change to it at all.我尝试了许多不同的程序,但似乎只要我对其进行任何更改,页面就根本不会加载。 However, any time I run the Feature Test, then reload the page in the browser, it'll show up fine.但是,任何时候我运行功能测试,然后在浏览器中重新加载页面,它都会显示得很好。 For reference, here's the test:供参考,这是测试:

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class AppTest extends TestCase
{
    /**
     * Testing that the app's main page loads successfully.
     *
     * @return void
     */
    public function test_app_home_page_loads_successfully(): void
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

What on earth is causing this odd behavior?到底是什么导致了这种奇怪的行为?

As @IGP and @matiaslauriti pointed out in the comments, there is clearly a permissions issue with storage/framework/views .正如@IGP 和@matiaslauriti 在评论中指出的那样, storage/framework/views显然存在权限问题。 However, it is not with the directory itself, just a single file (out of dozens) in that directory.但是,它与目录本身无关,只是该目录中的一个文件(几十个)。

I do not know how or why, but that one file ( 83b9b... ) had an owner:group of "root:root".我不知道如何或为什么,但一个文件( 83b9b... )有一个所有者:组“root:root”。 The rest of the files in that directory are owned by me and my group.该目录中文件的 rest 归我和我的团队所有。

What makes this odd is that this stays true even when I run the Feature Test, so I do not know why running that Feature Test causes the view to load fine even while that file is still owned by "root:root".奇怪的是,即使在我运行功能测试时这仍然是正确的,所以我不知道为什么运行该功能测试会导致视图加载正常,即使该文件仍归“root:root”所有。

Manually changing that file's owner:group does, indeed, fix the issue.手动更改该文件的 owner:group 确实可以解决问题。 My only concern now is not knowing how it got changed in the first place and, thus, not knowing how to prevent this from happening again in the future.我现在唯一担心的是不知道它是如何改变的,因此,不知道如何防止这种情况在未来再次发生。 If anyone has any ideas, I'm open.如果有人有任何想法,我很开放。 For now, however, I'll go ahead and close this.但是,现在,我将提前 go 并关闭它。

Thank you, @IGP and @matiaslauriti.谢谢@IGP 和@matiaslauriti。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM