Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Emokores's avatar

Cannot display image - Inertia with React

I have uploaded an image, which is supposed to be the logo for the app. However, when I try to reference the image in the <img /> it gives me HTTP 404. This is the address of the image: http://localhost:8000/storage/logo/AKmT9ziprZAfVeYePCADVe9q2UIqYcCuzb0irner.png


const {settings} = usePage().props

<img src={settings.logo} />

In my HandleInertiaRequests.php file I have:


'settings' => [
      'logo' => Storage::url(Setting::query()->first()->logo),
],

0 likes
24 replies
Sinnbeck's avatar

The url you are showing. Is that the url it is trying or the one you expect? Did you run php artisan storage:link?

1 like
Emokores's avatar

@Sinnbeck Yes. I run php artisan storage:link. My filesystem has been working well. That URL is the one the app is trying. I got it from the console, 'cause I had to see what Storage::url(Setting::query()->first()->logo) was giving me, so I did console.log(settings.logo), and the HTTP 404 error is giving me that URL.

Emokores's avatar

@Sinnbeck on the disk i Have /home/username/Workspace/project_name/storage/app/logo/AKmT9ziprZAfVeYePCADVe9q2UIqYcCuzb0irner.png

Sinnbeck's avatar

@Emokores So that url you posted works if you open it in the browser directly? Or what url should it be?

Sinnbeck's avatar

@Emokores Yes I get that. But what url can you access the image on if you just access it directly in the browser?

Sinnbeck's avatar

@Emokores Is the file in /home/username/Workspace/project_name/public/storage/logo/AKmT9ziprZAfVeYePCADVe9q2UIqYcCuzb0irner.png

Sinnbeck's avatar

@Emokores But it is in /home/username/Workspace/project_name/storage/app/public/logo/AKmT9ziprZAfVeYePCADVe9q2UIqYcCuzb0irner.png ?

Sinnbeck's avatar

Just read your answers again, and it seems that the file is not inside the public directory in storage. This meanas it isnt accessible from the web

Emokores's avatar

@Sinnbeck Exactly. The file exists in the storage folder under /app/logo/file_name.png

Emokores's avatar

@Sinnbeck No it's not in the public directory in the storage folder. So, how can I go about it? This is my update() method script:


if ($request->hasFile('logo')) {
    if (Storage::exists($setting->logo)) {
       Storage::delete($setting->logo);
    }

    $path = $request->file('logo')->store('logo')
}

kokoshneta's avatar

@Emokores If you’ve run php artisan storage:link without changing anything in the filesystem config, there should be a symlink in your public folder called storage (i.e., /public/storage) which points to /storage/app/public.

If you save your logo under /storage/app/logo, it won’t be accessible to the outside world, because it is located outside your document root – the server cannot serve it to the client. Remember that the entire /storage folder is located outside the /public folder, making it inaccessible to the outside world. Only the part of the storage folder which has a symlink inside the public folder is accessible, and by default that’s only /storage/public.

The easiest solution is to do what @sinnbeck says and simply save the logo inside /storage/app/public/logo/ instead of /storage/app/logo. Alternatively, if you want to keep your folder structure as is, you can create a symlink at /storage/app/public/logo which points to /storage/app/logo. You’d do this by editing your /config/filesystems.php file and adding an extra element to the links array:

// /config/filesystems.php
'links' => [
	public_path('storage') => storage_path('app/public'),
	public_path('storage/logo') => storage_path('app/logo')
]

– and then running php artisan storage:link again.

But that seems like unnecessary overkill to me.

Emokores's avatar

@Sinnbeck This is the URL I get, but the image cannot still display: /home/username/Workspace/project_name/public/logo/QuQkF4KCenTBoCXvwuLdPKxBSlniYJ4qcqJI8qgO.png

Emokores's avatar

@kokoshneta I did that, and it is now saved in the public folder. But I still can't get it to display. This is the path if use public_path() method: /home/username/Workspace/project_name/public/logo/QuQkF4KCenTBoCXvwuLdPKxBSlniYJ4qcqJI8qgO.png

kokoshneta's avatar

@Emokores But why are you using public_path() now? That just makes a fully qualified path based on whatever you give it as an argument.

What is Setting::query()->first()? Can you try to dump that with dd(Setting::query()->first() and show the result?

Emokores's avatar

@kokoshneta It is logo/QuQkF4KCenTBoCXvwuLdPKxBSlniYJ4qcqJI8qgO.png when I use Setting::query()->first()->logo

kokoshneta's avatar
Level 27

@Emokores Okay, in that case, Storage::url(Setting::query()->first()->logo) should also yield http(s)://localhost:8000/storage/logo/QuQ...png, which should be correct.

Is that what dd(Storage::url(Setting::query()->first()->logo)) shows?

Emokores's avatar

@kokoshneta It has worked. I used Storage::url(Setting::query()->first()->logo). I think public_path(), just as @sinnbeck noted, wasn't giving me the URL. Instead, it was giving me the disk. It was me mixing things up! It's now perfect. Thank you, guys! I deeply appreciate it.

Please or to participate in this conversation.