0

I have been struggling with this problem for quite a few hours. My problem is that I have an image url saved in my database and when i retrieve it I try to display it in my index.blade.php. The weird part is I had used the same code in an older project and it worked, but I turned on the older project and it does not work there anymore either. I have done php artisan storage:link and from what i see the link is correct but the images are displayed as broken, I have looked up various solution but all of it lead to a dead end, because the url just doesnt want to display the image. The image url is saved in this form http://127.0.0.1:8000/storage/public/vsX9ihmRknGWLXtNRmxgCXV3ckqhlFoBlyuMoejB.png

My index.blade.php tbody

  <tbody>
    @foreach($companies as $company)
        <tr>
            <td scope="row">{{$company->id}}</td>
            <td>{{$company->name}}</td>
            <td>{{$company->email}}</td>
            <td><img class="class='img-fluid rounded mb-3 mb-lg-0 ml-md-0" src="{{$company->logo}}"></td>
            <td>{{$company->url}}</td>
            <td>
                <a href="{{route('company.edit', $company->id)}}" class="float-left">
                    <button type="button"
                            class="btn btn-primary mr-2">{{__('Edit')}}</button>
                </a>
                <form action="{{route('company.delete',$company->id)}}" method="POST"
                      class="float-left">
                    {{method_field('DELETE')}}
                    @csrf
                    <button type="submit"
                            class="btn btn-danger btn-sn">{{__('Delete')}}</button>
                </form>
            </td>
        </tr>
    @endforeach
    </tbody>

How I call it from my Companiescontroller

 public function index(): Renderable
{
    $companies = $this->company->all();

    return view('company.index', compact('companies'));
}

How I store my image url

   public function store(Request $request): RedirectResponse
    {
    $request->validate([
        'name' => 'required',
        'email' => '',
        'logo' => 'dimensions:min_width:100,min_height:100',
        'url' => ''
    ]);
    $parameters = $request->all();
    if ($request->logo !== null) {
        $image = $request->logo->store('public');
        $parameters['logo'] = URL::to('/') . '/storage/' . $image;
    }
    $this->company->create($parameters);

    return redirect()->route('company.index');
}

I am not sure if this is enough, but i guess these are primary parts.

2
  • 1
    By default php artisan storage:link create a symlink with storage/app/public so move your image from storage/public to storage/app/public. Then you can access through http://127.0.0.1:8000/storage/vsX9ihmRknGWLXtNRmxgCXV3ckqhlFoBlyuMoejB.png Commented Oct 24, 2020 at 19:07
  • Thank you, you are a lifesaver Commented Oct 24, 2020 at 20:13

1 Answer 1

1

By default php artisan storage:link create a symlink with storage/app/public so move your image from storage/public to storage/app/public. Then you can access through http://127.0.0.1:8000/storage/vsX9ihmRknGWLXtNRmxgCXV3ckqhlFoBlyuMoejB.png

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.