mehrabt's avatar

image does not display in laravel v8

When I want to upload images to my Laravel project, they are placed in a database and storage\app\articles file, but I can't display them.

how can I fix it?

here is my code:

this is create.blade.php:
<div class="mb-3">
<label for="image">image</label>
<input type="file" class="form-control" name="image" id="image">
</div>

And this is show.blade.php:

<td>
  <img src="{{url('/storage/'.$article->image)}}" width="120px" height="60px" alt="">
</td>

and this is my postsController:

  public function store(CreateArticleRequest $request)
  {
      $image=$request->image->store('articles');
      //create the post
       $article=Article::create([
           'title'=>$request->title,
           'description'=>$request->description,
           'content'=>$request->content,
           'image' => $image,
           'published_at' => $request->published_at,
           'category_id' => $request->category,
          
           //'user_id' => auth()->user()->id
       ]);

       if ($request->tags) {
          $article->tags()->attach($request->tags);
        }
      //fetch the massage
       session()->flash('success','Post Created Successfully');
      //redirect user
       return redirect(route('cms.index'));
  }
0 likes
8 replies
jlrdw's avatar

Have you done a symlink yet?

1 like
mehrabt's avatar

yes, I used this command [php artisan storage:link] but images are putting in storage/app/articles and this command create a shortcut from storage/app/public for me

this is my problem

jlrdw's avatar

@mehrabt In documentation did you scroll down a little and read:

You may configure additional symbolic links in your filesystems configuration file. Each of the configured links will be created when you run the storage:link command:

1 like
Snapey's avatar

this line

$image=$request->image->store('articles');

change to

$image=$request->image->store('public/articles');

if you want the files to be externally accessible

You could create a new file system disk for this

1 like
mehrabt's avatar

@Snapey if i change this line of my code in the controller, laravel put this address into my database: public/articles/AG7xnycPiJ33r73fyQcnCegjKBKzNhapSHsNTIlz.jpg ,and images goes in this addres on my storage : public\storage\articles\AG7xnycPiJ33r73fyQcnCegjKBKzNhapSHsNTIlz.jpg but images is still doesn't show.

How can I show pictures ? i couldn't show it with <img src="{{ asset(.'/public/'.$article->image) }}" > and <img src="{{url('/storage/'.$article->image)}}" >

1 like

Please or to participate in this conversation.