Laravel Symbolic Link not working - laravel

I have some problems creating a symbolic link with laravel to access files that are in my storage
I am storing my files in
storage\app\public
I used the php artisan command to create the link
php artisan storage: link
The [public/storage] directory has been linked.
Earlier files were storing in storage\app\public and were also visible in public\storage folder
But now they are only storing in storage\app\public and not visible in public\storage folder
I am using link to show file path
{{ Storage::url($package->reportPath['path']) }}
Path is showing correct but it redirect to 404 page as there is no file I guess.

This solved it for me on laravel 8, hosted on a ec2 server.
rm public/storage
php artisan optimize:clear
php artisan storage:link

Try removing your public/storage directory and try running storage:link again. This worked for me.

If you are trying to Show the stored file use asset()
asset('storage/further_path/').$file_name;
To store file you can do
$destinationPath = storage_path('app/public/further_path');
if (!is_dir($destinationPath)) {
mkdir($destinationPath, 0777, TRUE);
}
$request->file->move($destinationPath,$filename);
Hope this Helps You.
Let me Know if You have any problem.

Related

Changes not showing up when changing a file in laravel

I have a file in my resources/lang folder and when I made a change to it, it didn't show up on my site.
I've tried php artisan cache:clear, php artisan config:clear, php artisan view:clear, but still no change
Try to clear views folder in Project/storage/framework. It might be an issue.
Have you tried your site on another browser ?

Cannot display image in vue.js

I'm saving image in following path :
storage\app\public\img\user_image
and saving image url like this in database:
/img/user_image/285070719.png
trying to display image like this:
<img :src="'../app/public'+profile.image">
but the image does not display, Any solution to resolve this issue is highly appreciated.
Have you create a storage link? php artisan storage:link https://laravel.com/docs/8.x/filesystem#the-public-disk
Then you should be able to use the uri like /storgae/img/user_image/285070719.png
Make sure that you created the symlink from public/storage to storage/app/public with php artisan storage:link, after that make sure that the generated URL is correct.
The following URL should be generated:
http://localhost:8000/storage/img/user_image/285070719.png
Something like the following should work for you:
<img :src="'/storage'+profile.image">
From the docs:
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. To create the symbolic link, you may use the storage:link Artisan command: php artisan storage:link

Laravel cached routes file access, version 5.8

Okay so I want to access the cached file of routes in Laravel version 5.8 I know that there is somewhere Laravel saves this file but I am not sure where to look for it.
I already tried to check the these folders
Storage
Bootstrap
But I couldn't find the route cache file. All I find is cached views and cached services and packages but there is no cache file.
Really Thank you for your time :)
It's in bootstrap/cache/routes.php.
The command php artisan route:cache or php artisan optimize (re)creates this file.
The command php artisan route:clear deletes this file.

Not Showing user avatar

HTML tag
<img src="storage/app/avatars/23_avatar1548246815.bmp" alt="">
File already exist on this path. But not showing.
And I used also this php artisan storage:link, but not working.
Error is Server Error 403 Forbidden.
According to laravel documentation.
The Public Disk
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.
To create the symbolic link, you may use the storage:link Artisan command:
php artisan storage:link
Of course, once a file has been stored and the symbolic link has been created, you can create a URL to the files using the asset helper:
echo asset('storage/file.txt');
thing I would do is definitely use this method
<img src="{{asset('assets/images/image.png')}}">
to link to your asset files.
Shouldnt the storage/app/avatars be storage/app/pubic/avatars ?
If you say that the file exists on that path, it points that the problem is with file permissions. Change the /project/storage permissions to 777, delete the public/storage folder, and run php artisan storage:link, then try one more time. If no, try to give 777 permissions to public folder

Laravel Artisan make command issue

I am trying to make a middleware using artisan php artisan make:middleware AuthorizedUserOnly but I get ErrorException like below.
file_get_contents(/mysite.com/www/local/composer.json) Failed to open stream no such file or directory.
This is my document root.
-local
-Laravel application folders
-artisan
-index.php
-composer.json
.htaccess
I changed my directory structure to work with shared hosting. And It was working fine.
KEY NOTES
Other artisan commands work. Like I tried php artisan route:list & php artisan config:cache & php artisan tinker.
This directory structure works fine.But as the error says that it is trying to find composer.json in local directory while it is on document root.
php artisan make:model command spits the same Exception
What could be the possible issue and solution ?
Solution : I moved my composer.json file to local directory and it worked fine. So new directory structure is
-local
-Laravel Application Folders
-composer.json
-artisan
-index.php
.htaccess
HOW ?
I am not sure about this yet. But this is the possible reason. php artisan make command create some files. So to included these created files into system execute composer dump-autoload. So to run composer it looks for in the same directory where artisan lives which is local directory in my case.
IMPORTANT
I changed laravel default directory structure to successfully run my applicaiton on SHARED HOSTING which laravel DOESNOT RECOMMEND.
We should follow the recommendations made by laravel to avoid any similiar issue. Specially never to mess with default directory structure at least.

Resources