eitibiti
eitibiti

Reputation: 45

Is there a way of calling my image from storage that is symlinked?

In my project, I have a image input on the register blade, and it gets stored by the code in the register controller:

            $profilepicture = request()->file('profilepicture')->getClientOriginalName();
            request()->file('profilepicture')->storeAs('profilepicture', $user->id . '/' . $profilepicture, '');
            $user->update(['profilepicture' => $profilepicture]);
        }

So, it goes into storage/app/profilepicture/(userid)/(picturename), as it's shown in the image:

enter image description here

Then, i want to call it in my approval view, which allows admin to change user status to active or inactive. All my infos work with the foreach, but i can't catch my image. Currently, i'm trying this code:

[<img  class="h-10 w-10 rounded-full" src="{{asset('storage/app/profilepicture/'.$user->id.'/'.$user->profilepicture)}}"/>
 ]

Which is into my table schema:

          <thead class="bg-gray-50">
            <tr>
              <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Identificação
              </th>
              <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                WhatsApp
              </th>
              <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Status
              </th>
              <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                Role
              </th>
              <th scope="col" class="relative px-6 py-3">
                <span class="sr-only">Alterar Status</span>
              </th>
            </tr>
          </thead>
          <tbody class="bg-white divide-y divide-gray-200">
              @foreach($users as $user)
            <tr>
              <td class="px-6 py-4 whitespace-nowrap">
                <div class="flex items-center">
                  <div class="flex-shrink-0 h-10 w-10">
                  <img  class="h-10 w-10 rounded-full" src="{{asset('storage/profilepicture/'.$user->id.'/'.$user->profilepicture)}}"/>
                </div>
                  <div class="ml-4">
                    <div class="text-sm font-medium text-gray-900">
                    {{ $user->name }}
                    </div>
                    <div class="text-sm text-gray-500   ">
                    {{ $user->email }}
                    </div>
                  </div>
                </div>
              </td> 
              <td class="px-6 py-4 whitespace-nowrap">
              {{ $user->phone }}
              </td>
              <td class="px-6 py-4 whitespace-nowrap">
                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                @if ($user->status == 0) Inativo @else Ativo @endif
                </span>
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                Admin
              </td>
              <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
              <a href="{{ route('status', ['id'=>$user->id]) }}" class="text-indigo-600 hover:text-indigo-900">@if ($user->status == 1) Inativar @else Ativar @endif
              </td>
            </tr>
            @endforeach
            <!-- More people... -->
          </tbody>
        </table> 

I already created the symlink to storage, but happens that I can't loop into the user id. For better understanding, there's a printscreen of my dev tools:

enter image description here

I'm still learning, so previously sorry for any rookie mistake.

Thanks for your time!

Upvotes: 0

Views: 50

Answers (1)

logmodia
logmodia

Reputation: 56

If you have already established the symbolic link ($php artisan storage:link) normally a link to your image is already created in the "public" folder (note that it is not the public folder that is in "storage" but rather the one located in the root of the project). And it is in the public folder of the root that you will look for your image. You can retrieve your image with the following syntax:

For example :

<img src='{{ Storage::url("assets/my-image.jpg") }}'>

//assets: is a folder located in "public/storage/assets" from the root.

And don't forget to check that your url is well formed (with a little dd())

Upvotes: 1

Related Questions