Helper Helper - 22 days ago 5
PHP Question

404 error in loading image: Laravel 5.1

When I am doing ?



In my Laravel 5.1 code, I created the Project with the name of SampleApplication...with the below path

C:\xampp\htdocs\SampleApplication\


Then after successful registration following directories are being created.

C:\xampp\htdocs\SampleApplication\Users

C:\xampp\htdocs\SampleApplication\Users\{UserName}
C:\xampp\htdocs\SampleApplication\Users\{UserName}\Profile
C:\xampp\htdocs\SampleApplication\Users\{UserName}\Profile\User.png


So far everything is ok.

What's the problem ?



In the dashboard page, I am trying to show the image like below.

<img src="{{url('/Users/' . auth()->user()->UserName . '/Profile/' .
auth()->user()->UserImage)}}" alt="..." class="img-circle profile_img">


This produces the below path.

http://localhost/SampleApplication/public/Users/UserName/Profile/user.png


What's the error ?



This is giving 404 error for the above image.

Am I missing something ?

Answer

Yes Laravel url default to public/, so for Laravel 5 or 5.1 rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder.

Give a try, It Should work!!