mardi 6 mars 2018

Laravel: Get correct path for public upload

I am using as recommended in the docs

$path = $request->file('avatar')->store('public/avatars');

to store my avatar. In the docs the following is mentioned:

By default, the store method will generate a unique ID to serve as the file name. The path to the file will be returned by the store method so you can store the path, including the generated file name, in your database.

Now the $path will be something like

public/pictures/uQT3sGS1mTQQXbB5vHwCYUiELtr2XAbl7cI08Mme.png 

but the actual url to the picture is

/storage/pictures/uQT3sGS1mTQQXbB5vHwCYUiELtr2XAbl7cI08Mme.png

In the docs its stated that I can store $path directly in the database. But as I see it, one has to convert manually

public/pictures/uQT3sGS1mTQQXbB5vHwCYUiELtr2XAbl7cI08Mme.png

to

pictures/uQT3sGS1mTQQXbB5vHwCYUiELtr2XAbl7cI08Mme.png

so that I can use it later like

<img src="/storage/"> 

Is there any Laravel option, so that store returns directly the correct link, or do I have to do this manually?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tmUUpD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire