Laravel storage link doesnt link with public - laravel

Try to upload my files to storage, and link it with my public folder.
I used
php artisan storage:link
Then, I upload photos like below;
$filename = uniqid().".".$file->getClientOriginalExtension();
$filePath = 'uploads/announcement';
Storage::disk('public')->putFileAs($filePath, $file, $filename, ['visibility' => 'public']);
$announcement->photo = $filename ?? $announcement->filename;
But my /public/storage folder is empty, when I upload files.
Whats wrong with it?
My filesystem.php is below;
'public' => [
'driver' => 'local',
'root' => storage_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],

this is the way i do it (i n livewire but the storePubliclyAs Is not livewire)
if($this->image != null){
$imageName = time().'.'.$this->image->extension();
$company->image= $imageName;
// on upload l image dans le folder
$this->image->storePubliclyAs('companylogos',$imageName);
}
companylogos is the name of the folder in (storage/app)
i had same problem as you first ! you need to make sure your folder is linked , for that you need to see a little logo on the folder like a link logo meaning that the two folders are sync (linked) , the error is to create both files and try to link them , no you have to create only the storage/app/companylogos folder first and then use artisan to link php artisan storage:link
of course you need to have prepared your file in config filesystems, this is how i did it
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('profilecv') => storage_path('app/profilecv'),
public_path('companylogos') => storage_path('app/companylogos'),
],

I think you have to change file system
filesystem.php is below;
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],

Related

My uploaded image doesn't save in the storage file

I've followed the steps of Laracasts, but it's not working.
When I submit the form it returns:
Done: storage/thumbnails/k0TF3NW6WvWWjHuEtZ0OW7TTRQbfSB6lvD1GJls3.png
But I couldn't find it anywhere. My storage/thumbnails is empty.
My Controller:
$path = request()->file('thumbnail')->store('storage/thumbnails');
return 'Done: ' . $path;
My filesystems.php
'default' => env('FILESYSTEM_DRIVER', 'public'),
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
How can I find the uploaded file? Thanks!
Could you try this code please.
$file = $request->file('thumbnail');
$file_name = uniqid()."_".time().'.'.$file->extension();
$file_location = '/thumbnail/';
$file-> move(storage_path($file_location), $file_name);
I hope the code helps you. Have a good one :)
Have you tried "php artisan storage:link" command?

Laravel file from storage not found

Filesystem settings
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Upload file
$path = $request->file('file-upload-photo-profile')->store('public/profile');
$user->photo_profile_url = Storage::url($path);
Patch to folder with file:
storage/app/public/profile
Example url:
Try get image:
<img src="{{asset( $user->photo_profile_url)}}" >
Generated url:
http://sakura/storage/profile/aDtjR6z7Ih4fkmo7bdAqqyDXmhu2qE4pg3s5BBla.jpg
But I got 404 for this image.
In server settings root dirrectory
public
How do I get a link to an image?
Do you have the symlink to the storage folder in your app/public directory?
Like so: php artisan storage:link

Image URL issue in Larval 7

I am trying to hide the Image URL Larval 7 Application.
My image actual path is
storage/app/public/images/product_images
I have created a storage link using bellow command
php artisan storage:link
this creates a symbolic link in public directory "storage" to "storage/app/public/"
After that, I have created a new disk in config/filesystems.php
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'url' => env('APP_URL') . '/images',
'visibility' => 'public',
],
in my view I have written this code to access the image
<img class="img-fluid" src="{{Storage::disk('images')->url('/product_images/'.$products_image)}}">
$products_image is getting the correct image name but the image is not showing.
Is it possible to achieve what I am trying to achieve?
and what I am doing wrong?
You are missing the storage part of the URI for the url for that disk in the configuration.
fix your url env('APP_URL') . '/storage/images' as it is stored in storage_path() so you need to append storage
`
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'url' => env('APP_URL') . 'storage/images',
'visibility' => 'public',
],

LARAVEL 7 - Image not showing after config:clear

I'm working on Laravel 7 (using Laragon 4.0 on Windows 10), I have some file download and save from remote urls. Everything was working fine but I had to perform a "php artisan config:clear" to update mysql configuration and after that the images saved in storage/public folder are not served anymore.
The files were there but just not served, then I deleted everything inside /storage/public folder, deleted the symlink inside /public folder to /storage (naturally performing "php artisan storage:link") and populate again /storage/public with folders and file like I did previously. The folder structure is there, the files also but when I try to access them I get 404 error.
I tried "php artisan optimize:clear" and every suggestion I found on stackoverflow but nothing seems to help me, I don't know where to look, please help me.
Here is the code I use to download/save images:
$url = $team["logo"];
$contents = file_get_contents($url);
$name = substr($url, strrpos($url, '/') + 1);
$file = 'public/team/logo/'. $name;
Storage::put('team/logo/'. $name, $contents);
This is how I display images on the view:
<img src="{{Storage::url($team->logo)}}" style="max-width:50px">
This is my public disk configuration on filesystems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
As your driver is set to
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Your Storage::disk('local') is, in absolute terms, set to /storage/app/public. Hence $file = 'public/team/logo/'. $name; becomes $file = 'team/logo/'. $name;
In case you are using the Intervention/Image library, you may consider to change
$contents = file_get_contents($url);
to
$contents = File::make($url);
see http://image.intervention.io/api/make

Laravel 5.6 store() disk stays the default one

I used this method before to specify path to my storage folder inside public folder to store images:
$file->store('storage/cars/' . $img . 'uploads')
And in config/filesystems.php
'uploads' => [
'driver' => 'local',
'root' => public_path(),
],
It worked before and now even if I add this it uploads to storage/app/storage/cars as it's on default.
ANSWER
$file->store('storage/cars/' . $img , 'uploads')
I had dot instead of comma.
This directly uploads to public folder.
public_path() outputs storage/app, thats why after you execute store it will be saved on storage/app/storage/cars, so what you want is to specify the path to be just storage ->
'uploads' => [
'driver' => 'local',
'root' => public_path().'/storage
]
Then when you want to save the file you could do this:
$file->store('cars/' . $img , 'uploads')

Resources