Why Storage Class doesn't have a storage() helper function ITS A NEED!! :D

Published 2 months ago by skeith22

I'm lately creating a project that involves uploading a lot of files and displaying them specially images.

its kinda bothersome that you need to include

use Illuminate\Support\Facades\Storage

in almost all of your controllers cause you need the function

Storage::url()

for you to display images in your view cause you need to generate the url for it. Instead of using a helper. If we have

storage()->url()

we don't need to include

use Illuminate\Support\Facades\Storage

we could just use the storage() helper function to generate the url in the views to pull files in the Storage.

It would really be nice and helpful to have a storage() helper function.

I'm referring to generating the url for the file.

If anyone encountered this you guys could just include the

use Illuminate\Support\Facades\Storage

in the Controller Class which is being extended by all Controllers

Snapey
Snapey
2 months ago (618,705 XP)

Do you mean like storage_path()

https://laravel.com/docs/5.4/helpers#method-storage-path

or is it the URL you are after? This will be specific to the type of storage

skeith22

@Snapey the url for you to display it on the view.

Snapey
Snapey
2 months ago (618,705 XP)

So it depends on your storage tech. If you are using S3 then the path will be very different to if you are using local storage.

If local, and you have correctly symlinked the folder then you can always use the asset() helper

Snapey
Snapey
2 months ago (618,705 XP)

The other thing you could consider is if you have say, an image class, then add the url as an attribute of your image via an accessor. You can then use it like <img src="{{$image->url}}">

skeith22

@Snapey hmmm..let me see I'll try again using the asset() helper.

but Storage::url() clearly goes with using the

request()->picture->store('public/your_folder');

or

request()->image->store('public/your_folder');

or

request()->photo->store('public/your_folder');
jlrdw
jlrdw
2 months ago (191,810 XP)

You of course do realize a "helper" as you call it takes 3 seconds to create a constant, like

define('DIR', '/my-site-folder-for-example/');

then

<img src="<?php echo DIR . 'upload/imgdogs/' . $row->dogpic; ?>" alt="" class="image">

Taylor doesn't know all the places people want to store images and files.

Sorry, just have to say, geeze.

EDIT:

its kinda bothersome that you need to include

use Illuminate\Support\Facades\Storage

I have never ever had to use that to display an image.

skeith22

@jlrdw thanks for the reply I already found the solution for it.

Sign In or create a forum account to participate in this discussion.