Laravel file from storage not found - laravel

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

Related

Laravel storage link doesnt link with public

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',
],

Laravel route issue in subfolder

I have installed laravel 5.4 app at https://wolvecapital.com/muazzamazaz/
its getting web page of https://wolvecapital.com after login or register
For example inside web.php
Route::post('/sign_in' , 'UserApiController#signin'); this should get web page inside muazzamazaz resources but it getting main website page
I have put public folder files at root of muazzamazaz and all other files inside muazzamazaz/justcabbie folder
path setting inside index.php is:
require __DIR__.'/justcabbie/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/justcabbie/bootstrap/app.php';
all other settings are not changed
filesystem.php is:
'local' => [
'driver' => 'local',
'root' => storage_path('app/public'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
since files are also not being stored in directory

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

How to create Laravel Storage link to root after remove public folder

I removed public folder Now I want to create storage link to root folder name upload
filesytems.php
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/upload',
'visibility' => 'public',
],
When I use php artisan Storage:link it's create a public folder. But I don't want this.
I also try
ln -s storage/app/public upload
But got error massage
'ln' is not recognized as an internal or external command,

Resources