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

Time:02-03

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   src="{{asset('storage/app/profilepicture/'.$user->id.'/'.$user->profilepicture)}}"/>
 ]

Which is into my table schema:

          <thead >
            <tr>
              <th scope="col" >
                Identificação
              </th>
              <th scope="col" >
                WhatsApp
              </th>
              <th scope="col" >
                Status
              </th>
              <th scope="col" >
                Role
              </th>
              <th scope="col" >
                <span >Alterar Status</span>
              </th>
            </tr>
          </thead>
          <tbody >
              @foreach($users as $user)
            <tr>
              <td >
                <div >
                  <div >
                  <img   src="{{asset('storage/profilepicture/'.$user->id.'/'.$user->profilepicture)}}"/>
                </div>
                  <div >
                    <div >
                    {{ $user->name }}
                    </div>
                    <div >
                    {{ $user->email }}
                    </div>
                  </div>
                </div>
              </td> 
              <td >
              {{ $user->phone }}
              </td>
              <td >
                <span >
                @if ($user->status == 0) Inativo @else Ativo @endif
                </span>
              </td>
              <td >
                Admin
              </td>
              <td >
              <a href="{{ route('status', ['id'=>$user->id]) }}" >@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!

CodePudding user response:

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())

  •  Tags:  
  • Related