crudbooster, How to change storage path in laravel to public? - laravel

I use crudbooster admin generator in laravel 5.4, if I upload a file from a form, it will be stored in own storage directory. Then I should create a symlink to that storage path in public path.
I can't use creating symlinks on my system because of the limitation. How can I upload files directly to public/uploads instead of storage/app/uploads?

I honestly have no clue. Best I can do is point you in the right direction. Crudbooster depends on a package called UniShard/laravel-filemanager. I was looking through the config file for this package and it is similar to the lfm.php in your config folder except there are more options. Perhaps you could use one of these additional options such as base_directory. Not sure how this will work out and it could just be poorly coded.
Original Answer:
You need to create a new disk.
In config\filesystems.php, add this.
'disks' => [
'uploads' => [
'driver' => 'local',
'root' => public_path() . '/uploads'
],
],
Now, when you want to use the storage facade you can just do this:
Storage::disk('uploads');
An example usage:
Storage::disk('uploads')->put('filename', $file_content);
Hope this helps.

we can change it in
vendor/crocodicstudio/crudbooster/src/controllers/cbcontroller.php line: 1010

Related

Laravel - Saving Images To New Disk Returns 404 - How To Resolve (Laravel Media Library)

I have multiple disks set up within config/filesystems.php like so: I have recently added 'mealimages'.
'menus' => [
'driver' => 'local',
'root' => storage_path('app/menus'),
'url' => env('APP_URL').'/menu-store',
'visibility' => 'private',
],
'mealimages' => [
'driver' => 'local',
'root' => storage_path('app/meal-images'),
'url' => env('APP_URL').'/meal-images-store',
'visibility' => 'public',
],
I'm using laravel media library to handle my image uploads, in my model, I have configured the collection to use the mealimages disk like:
$this->addMediaCollection('meal-image')->useDisk('mealimages')->singleFile();
I have flushed application cache by running php artisan optimize:clear, tried deleting my /public/storage directory and re-ran php artisan storage:link to try and get the images to show once they have been uploaded. I can confirm that the images are being stored correctly within my storage directly but the URL generated by laravel media library for the image returns 404.
I have also tried updating the visibility but no luck.
I am able to get the functionality and image uploads working correctly and showing if I update the ->useDisk() on the model to use the 'menus' disk.
$this->addMediaCollection('meal-image')->useDisk('menus')->singleFile();
I'm struggling to figure out why its working for the menus disk but not my mealimages disk? What I am missing in order to set up a new filesystem to use?
Any help would be great? Thanks

How to configure filesystems to send images from one Laravel application to another?

My application consists of two different laravel applications.
One, (APP-A) is the front end for users.
Another (APP-B) is the backoffice, used only by content managers.
Both consume the same database.
The problem to be solved has to do with the storage of images and other files.
During development, I want to store the images in APP-B storage.
For this, I need to send the images from APP-A to APP-B and perform the other applicable CRUD operations.
How should I configure filesystems.php for this purpose? Do I have to do it in APP-A and APP-B filesystems? And file .env?
EDITED 17/03
APP-B (backoffice)
Folders:
Storage/uploadFiles/images
filesystems.php
uploadFiles' => [
'driver' => 'local',
'root' => storage_path('app/uploadFiles'),
],
'links' => [
public_path('uploadFiles') => storage_path('app/uploadFiles')
],
On APP-B controllers to read images from APP-B storage
$url = asset('images/');
On APP-A (Front End for users)
.env file
ASSET_URL= http://my_app.dv/uploadFiles/
Note: php artisan config:clear required
For read images stored in APP-B from APP-A controller , just:
$url = asset('images')
It works.
Problem to solve: store a image in APP-B storage from a APP-A controller
$file = $request->file('file');
$path = $file->store('images');
This will store in APP-A instead of App-B as desired.
How to solve this (for development purposes only)?
You can set up AWS S3 for both applications and use the same key in both applications to access the same bucket. Result: Both applications uses the same "storage directory".

How to overwrite images via FTP upload in Laravel

I have a third party Laravel project with a function to upload images.
The function generates an operator folder, category sub-folder and product sub-sub-folder with a product image within.
There is no resize option here, so many files are 4MB or more.
I wrote a simple bash script to resize the images and tried to upload them via FTP: now all the files are around 100Kb on the server but in browser inspector I still have 4MB image.
I tried artisan clear:clear and view:clear.
No results.
I even tried to delete one or more images and to rename the entire category folder but browsers are still capable to visualize large images with the same old url. (???)
Cache were cleared on the client side.
The main folder is public/storage/image/
The filesystem.php in config folder says:
return[
'default' => env('FILESYSTEM_DRIVER', 'public'),
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public'
],
]
How can laravel show images when I rename/delete folders and images or (better) what am I missing?

Understanding file storage and protecting contents Laravel 5

I need help understanding Laravel's file storage system. I'm creating an app where I need to upload a users drivers license photo. This is obviously sensitive information. I would like to keep this image off of the internet unless an admin is viewing it. My understanding is that i have to save things to the public directory in the storage>app>public and create a symlink to the public>storage folder. I have this done and it's working fine. I save the path to the database and the program can display it, but I don't want things to be in the public folder if I can avoid it.
Is there any way to save an image/file to a private folder in the storage system then access it through the view? If I do this, does it keep that image "private" so that it's not stored in a cache somewhere beings that it's not in a "public" folder? Does the symlink protect files in the storage folder in the way I'm wanting or does it truly make all files available to the public?
Any help in understanding this would be appreciated.
What you've said is correct the files in storage/app/public is public. This is why you have to create a private directory, lets say storage/app/private, then upload your sensitive files here.
You may want to add a disks in your config/filesystems.php:
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
],
If you want to access your private files. Create a route for this:
Route::get('/private-files/{file?}','FileController#get')->where('file', '(.*)');
Then in the FileController.php, you will have something like this (this is just an example, edit the code here to check if the user is admin):
<?php
namespace App\Http\Controllers;
use Auth;
use Storage;
use App\Http\Controllers\Controller;
class FileController extends Controller {
public function __construct()
{
$this->middleware('auth');
}
public function get($file)
{
return Storage::disk('private')->get($file);
}
}

Laravel use S3/CloudFront resources in Blade

I'm a bit confused about what the best approach is in order to access an image, which is uploaded to S3 and delivered via CloudFront and show it in a view (using the CloudFront URL). I use Laravel 5.5 and I deposited the CDN URL already to my S3 configuration:
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => 'https://xxxxxx.cloudfront.net/',
],
The following possibilities work
Copy and paste the CloudFront link into the template (not the laravel way, I guess).
Using <img src="{{ Storage::url('assets/img/image.png') }}" />. This one works, but is it the right approach? The problem here is, that if I change the FILESYSTEM_DRIVER back to local I can't reference the resources in my DOCROOT/public/img folder like I did earlier with {{ asset('img/icons/time.png') }}, so I'm loosing flexibility - maybe I need to copy the assets to DOCROOT/storage/app/public/ which used by the local driver?
I'm integrating CloudFront the first time to a Laravel app, so could someone who did that before tell me what the right approach is? Thank you very much.
This is a good approach. But when using the local filesystem driver, you would use the public/storage/assets/img directory, not the public/img directory to make it equivalent.
https://laravel.com/docs/5.6/filesystem#the-public-disk
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
File URLs
You may use the url method to get the URL for the given file. If you are using the local driver, this will typically just prepend /storage to the given path and return a relative URL to the file. If you are using the s3 or rackspace driver, the fully qualified remote URL will be returned:

Resources