Image URL issue in Larval 7 - laravel

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

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 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

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

Shared Hosting Laravel 8 Hosting problem: Symlink is not working

I need the deploy my laravel project to the web. With this introduction But the hosting provider is Doesn't allow me to use a symbolic link(symlink), I called customer service, and told me blocked for security reasons.
So, since I do not use symbolic links, there are big problems in uploading images and deploying them.
Is there a way to do deployment my app?
Change your disk configurations in the config/filesystems.php to read and write to public folder via public_path() function.
If you're deploying over a shared host, you probably have another folder like public_html as your public folder which is not included in your source. Try to link to the public_html using dots ../../public_html/
'public' => [
'driver' => 'local',
// 'root' => storage_path('app/public'),
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
],
'photos' => [
'driver' => 'local',
'root' => public_path('photos'),
'url' => env('APP_URL') . '/photos',
'visibility' => 'public',
],
Another way is just create something like symlink using php, example you can create a route like below:
Route::get(
'/storage/{file}',
function ($file) {
$filepath = "../storage/app/public/".$file;
header("Cache-Control: public");
header("Content-Type: ".mime_content_type($filepath));
header('Content-Length: '.filesize($filepath));
readfile($filepath);
die();
}
);
Maybe not best practice, but it will solve your problem. It's will do same as symlink.

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