Laravel add two directories to local disk - php

Filesystem.php
How can i add another directory to local disk.
Currently only having the images directory
'disks' => [
'local' => [
'driver' => 'local',
'root' => public_path('images/'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],

You can only specify the root of each disk defined in config/filesystems.php. You are free to define as many disks as needed however:
'images-subdir' => [
'driver' => 'local',
'root' => public_path('images/subdir'),
],

If I understand your question correct, you need:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
]
Source: https://github.com/laravel/laravel/blob/master/config/filesystems.php

Related

Facing 403 error while uploading images on my sites dashboard

I am having issue whenever I upload image from my site's admin dashboard.
It's always 403 error.
I have all my possible best but no way.
This is the code in the filesystem.php. Please help, what am I not doing correctly?
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
],
//---
// Used for Admin -> Log
'storage' => [
'driver' => 'local',
'root' => storage_path(),
],
// Used for Admin -> Backup
'backups' => [
'driver' => 'local',
'root' => storage_path('backups'), // that's where your backups are stored by default: storage/backups
],
I think CSRF is missing in this form.

calling asset on production env didn't work Laravel 8 (shared hosting)

hello there I'm having trouble with calling my asset in the production environment this is how the structure of the folder
Laravel/
storage
...
public_html/
storage(a symlink that I created and working fine using, ln -sfn
domains/sites.com/new/storage/app/public/posted-images/ ../public_html/)
...
and this is how I call the asset :
<img src="{{ asset('storage/'.$posts->image) }}" alt="" class="img-fluid">
this is how my filesystem.php looks a like :
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
and in .env I put :
FILESYSTEM_DRIVER = public
So I found the solution like this :
first I'm deleting the storage link that I created with ln -sfn domains/sites.com/new/storage/app/public/posted-images/ ../public_html/
then, in filesystem.php change :
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
to
'public' => [
'driver' => 'local',
'root' => 'storage',
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
after that, make a request to store function and it will create the storage folder in public_html. Your old file maybe not gonna appear there so(file before you change the root to 'storage'), you can copy the data that not there from storage folder in the domain.
And the way i call the asset is the same as above.

(InvalidArgumentException(code: 0): Disk [public] does not have a configured driver Voyager

I'm getting this error when I uploaded my project on a centos server
(InvalidArgumentException(code: 0): Disk [public] does not have a configured driver
Everything is correct in filesystem.php:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'public' => [
'driver' => 'local',
'root' => public_path('storage'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
and in voyager.php :
'storage' => [
'disk' => 'public',
],
what should I do?
I have uploaded the same config files to the server, literally with no change and it worked...

laravel image url not redirecting to home page

Hi everybody in my laravel project the url of any image like
http://kemakon-app.com/storage/images/Screenshot_10.png is redirected to homepage storage link but still getting the error any idea why
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'visibility'=> 'public',
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],

Laravel Storage::disk()->url(); does not work properly

Hello i have a trouble in laravel.
i wanna create private storage for some stuff (xls,image,pdf, etc).
Everything works great in storage/app/public directories but i dont want it, i want my directory like storage/app/products/{id}/
at first look at my code:
filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'productions' => [
'driver' => 'local',
'root' => storage_path('app/productions'),
'visibility' => 'private',
],
i create new array 'productions'
ProductionController.php
public function file()
{
return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';
}
web.php (Route)
Route::group([
'middleware'=>'roles',
'roles'=>['Administrator','Prefabrykacja','Dyrektor Prefabrykacji']
], function () {
Route::get('/Produkcja',[
'uses'=>'ProductionController#index',
'as'=>'production.index']);
Route::post('/Produkcja/create',[
'uses'=>'ProductionController#create',
'as'=>'production.create']);
Route::get('/Produkcja/file',[
'uses'=>'ProductionController#file',
'as'=>'production.file']);
});
if i return
return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';
Or
return '<img src="'.Storage::disk('local')->url('7/2.png').'">';
result is the same. both line return the image from storage/app/public/7/2.png will display not image storage/app/products/7/2.png
how can i display the image from my products folder and restrict resources to specifed role?
Regards
First of all, you're probably missing a symlink like this one for public (Local URL Host Customization). Also, you need to specify url parameter like for public and change visibility to public in order to allow others to see your files.
filesystem.php:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'productions' => [
'driver' => 'local',
'root' => storage_path('app/productions'),
'url' => env('APP_URL') . '/productions', // added line (directory within "public")
'visibility' => 'public', // modified visibility
],
],
Also make sure that you create a symlink at public/productions which will point to storage/app/productions directory. You can do this by using following command (for example):
cd LARAVEL_PATH && ln -s storage/app/productions public/productions

Categories