mateog98's avatar

I upload a post and the image is not being visualized

Im uploading posts that are images and they are being stored in my storage folder but they are not being visualized in my browser. It appears as if there is a post but the image is not being showed.

I already have a storage:link.

This is my store function in my PostsController:

	public function store (Request $req) {
    		$rules = [
        "image" => "required|image",
        "description" => "string",
        "user_id" => "integer"

    ];

    $this->validate($req, $rules);



    $post = New Post();

    $post->image = $req->file('image')->store('/');

    		$post->description = $req->description;
    		$post->user_id = $req->user()->id;




	        $post->save();


    		return redirect("/post/" . $post->id);
		}
0 likes
10 replies
vincent15000's avatar

The solution is perhaps how you are calling the UR to access to the stored imaged to display them.

Can you share you blade code ?

mateog98's avatar

@vincent15000 This is my posts.blade.php

<ul style="list-style-type: none" class="list">
	@forelse($posts as $key => $post)

	<div class="postContainer">
    	<div class="photoProfileContainer">
        	<img class="profilePicture" src="../../../storage/avatar/{{$post->user['avatar'] }}">
        	<div class="userName">
            	<h2>
                	<a style="color: black; font-size: 15px" href="/user/{{$post->user->id}}">		{{$post->user["userName"]}}
                    </a>
	            </h2>
    	        <p>{{ $post->created_at->diffForHumans() }}</p>
        	</div>
    	</div>
    	<div class="postImage">
        	<img class="photoContainer" src="../../../storage/avatar/{{$post['image'] }} ">
    	</div>

    	<div class="description">
        	<p >
            	{{$post->description}}
            <span>
                <a href="/post/{{$post->id}}">
                    <i style="font-size:14px" class="fa fa-plus"></i>
                </a>
            </span>
        </p>

        <div class="postIcons">
            <div class="postIcons-heart">
                <a class="buttons" type="button" onclick="increaseValue()" id="like" name="button">
                    <i class="fa fa-thumbs-up">
                        <span id="clicks">0</span>
                    </i>
                </a>
            </div>
            <div class="postIcons-comment">
                <a class="buttons" type="button" onclick="showHideComments()" name="button"><i class="fa fa-comment"> 12</i></a>
            </div >           
        </div>
    </div>

The images are being stores at storage->app->public->avatar

Sinnbeck's avatar

@mateog98 you need to use the absolute path from the public directory

src="/storage/avatar/{{$post->image }} "
vincent15000's avatar

@mateog98 You should add a symlink from the public app folder to the storage folder where your images are stored.

php artisan storage:link

The storage folder is not accessible from the browser.

mateog98's avatar

@vincent15000 yes i did. $ php artisan storage:link The [C:\Users\Mateo\OneDrive\Desktop\Proyectos\MyFuture\MyFuture\public\storage] link already exists. The links have been created.

Still doesn´t work. I´ve been trying running storage:link all day

1 like
vincent15000's avatar

@mateog98 Obviously you try to display an image from the storage folder.

http://localhost:8000/storage/avatar/dpIyWFuzcDCyAin7oKTCB5TVZ3Z9J1JdPzs5TuYK.jpeg

I wonder if the public link is correctly declared.

Can you show the filesystems configuration file ?

mateog98's avatar
mateog98
OP
Best Answer
Level 1

The solution was to delete the storage folder inside public and run again php artisan storage:link

2 likes

Please or to participate in this conversation.