#Accessing image in public still works without symlink (Explanation please)

9 messages · Page 1 of 1 (latest)

fast viper
#
<?php
class RegisteredUserController extends Controller
{
    public function store(*Request $request*): RedirectResponse
    {
        $request->validate([
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'lowercase', 'email:strict,dns', 'max:255', 'unique:' . User::class],
            'password' => ['required', 'confirmed', Rules\Password::defaults()],
            'profile' => ['required', 'image', 'mimes:jpeg,png', 'max:2048'],
        ], [
            'profile.max' => 'The profile image must not be larger than 2MB.',
        ]);
        if ($request->hasFile('profile')) {
            $profilePath = $request->file('profile')->store('profiles', 'public');
        }
        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password),
            'profile' => $profilePath,
        ]);
        event(new Registered($user));
        Auth::login($user);
        return redirect(route('dashboard', absolute: false));
    }
}

example profile value in user:
profiles/CKyXwwZFVGJ5ghhkfUBQfXDsMgw4eliC2iz8YFLN.jpg

why i can do thses 3 without even php artisan storage:link and they still works, i can still see the image?:

<img src="{{ auth()->user()->profile }}" />
<img src="{{ asset(auth()->user()->profile) }}" />
<img src="{{ asset('storage/' . auth()->user()->profile) }}" />

the image is stored in the `storage/app/public/profiles/filename.jpg' (note that i haven't symlink it yet and i haven't configure the filesystems.php)

undone sandal
#

Please show the output of "ls -la public" to confirm that there's no symlink.

#

Also show a concrete example of an img tag url.

fast viper
#

Hello, Thank you for taking an interest in this discussion

<img src="{{ auth()->user()->profile }}" />
<img src="{{ asset(auth()->user()->profile) }}" />
<img src="{{ asset('storage/' . auth()->user()->profile) }}" />

corresponds to the following URL

http://homeroom.test/profiles/CKyXwwZFVGJ5ghhkfUBQfXDsMgw4eliC2iz8YFLN.jpg
http://homeroom.test/profiles/CKyXwwZFVGJ5ghhkfUBQfXDsMgw4eliC2iz8YFLN.jpg
http://homeroom.test/storage/profiles/CKyXwwZFVGJ5ghhkfUBQfXDsMgw4eliC2iz8YFLN.jpg

I know that i should use storage:link since i am storing the image in the public disk, i even look for the public/storage/ directory to make sure that i haven't symlink already. So this seems a bit odd

$ ls -la public
total 19
drwxr-xr-x 1 My Name 197609   0 May 20 18:44 ./
drwxr-xr-x 1 My Name 197609   0 May 19 21:14 ../
-rw-r--r-- 1 My Name 197609 740 May 11 18:55 .htaccess
drwxr-xr-x 1 My Name 197609   0 May 20 17:29 build/
-rw-r--r-- 1 My Name 197609   0 May 11 18:55 favicon.ico
-rw-r--r-- 1 My Name 197609  17 May 20 18:08 hot
-rw-r--r-- 1 My Name 197609 543 May 11 18:55 index.php
-rw-r--r-- 1 My Name 197609  24 May 11 18:55 robots.txt
drwxr-xr-x 1 My Name 197609   0 May 20 18:44 vendor/
undone sandal
#

That's surprising to me. Especially if the urls without /storage also work. What web server are you using?

fast viper
#

I am using Laravel Herd on windows so Nginx if that affects something

fast viper
#

I created another project and tested this again, the same setup, laravel new imagebugtest no starter kit, then I composer require laravel/breeze --dev then php artisan breeze:install

Then in dashboard.blade.php

<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Dashboard') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <img src={{ auth()->user()->profile }} />
                <img src={{ asset(auth()->user()->profile) }} />
                <img src={{ asset('storage/' . auth()->user()->profile) }} />
                <div class="p-6 text-gray-900">
                    {{ __("You're logged in!") }}
                </div>
            </div>
        </div>
    </div>
</x-app-layout>

corresponds to the following src when inspected:

<img src="profiles/dmciGSr4LOEXVcyr5iIpyU3b14eWEEFzuvYHCIzz.png">
<img src="http://imagebugtest.test/profiles/dmciGSr4LOEXVcyr5iIpyU3b14eWEEFzuvYHCIzz.png">
<img src="http://imagebugtest.test/storage/profiles/dmciGSr4LOEXVcyr5iIpyU3b14eWEEFzuvYHCIzz.png">
fast viper
undone sandal
#

Not a Herd user myself. Maybe they're doing some magic, but I can't find any information. Maybe try changing APP_URL to http://localhost:8000 and run composer dev. Just to check if also happens on the builtin server.