简体   繁体   中英

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. I've created some migrations and seeders and they run perfectly with 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. I give it the contents of "Hello World." That's it. No boilerplate, no HTML, nothing. I update the main "/" route to point to "index" instead of "welcome". I then create a Feature Test to make sure that getting the "/" route returns a status code of 200. It runs great. The page also loads fine in a browser displaying the "Hello World" text.

Now comes the part where I get confused. I change the "Hello World" text to just say "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 . 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". The rest of the files in that directory are owned by me and my group.

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".

Manually changing that file's owner:group does, indeed, fix the issue. 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.

Thank you, @IGP and @matiaslauriti.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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