laravel / nova-issues

554 stars 35 forks source link

Custom CSS using Nova::style on sail - file not found #3499

Closed powellblyth closed 3 years ago

powellblyth commented 3 years ago

Description:

I'm running Nova on Sail, and I wanted to add a custom button colour. I followed @davidhemphill 's video up to 1:20 to try and get any css file to show https://www.youtube.com/watch?v=InK-mRH9z5M&t=85s However, http://localhost:6080/nova-api/styles/elasticutNova gives me

ErrorException
file_get_contents(http://localhost:6080/css/elasticutNova.css): Failed to open stream: Cannot assign requested address

However, from my browser, I can access this URL http://localhost:6080/css/elasticutNova.css just fine

I think it's to do with PHP inside Sail trying to access the external address using file_get_contents, and failing, because it's obviously not a docker address

this is from vendor/laravel/nova/src/Http/Controllers/StyleController.php:28

public function show(NovaRequest $request)
    {
        $path = Arr::get(Nova::allStyles(), $request->style);
        abort_if(is_null($path), 404);
        return response(
            file_get_contents($path),
            200,
            [
                'Content-Type' => 'text/css',
            ]
        )->setLastModified(DateTime::createFromFormat('U', (string) filemtime($path)));
    }

Detailed steps to reproduce the issue on a fresh Nova installation:

crynobone commented 3 years ago

Please follow guide from our documentation, above video was release 2 years ago and using asset() with file_get_contents() would require you to enable allow_url_fopen

https://www.php.net/manual/en/function.file-get-contents.php#refsect1-function.file-get-contents-notes