return url('images', $image->name);
// http://localhost/images/image-name.png
After uploading image in laravel get the image url
How to after uploading image in laravel get the image url ?
@Sergiu17 Thanks but does not work if i use it on shopify Can you suggest some steps that make work just like using third party sites that after I upload image on laravel inputs then i got image url then accessible online thanks
@friedrich Well that completely depends on how you’re uploading images.
@martinbean What i want is after uploaded it on laravel storage how can i get the image url that can access online?
@Friedrich And what I want is for you to actually show how you’re currently uploading files, so I can then advise you on the best way to get the URL for that file.
$product = new ImageProducts;
$product->user_id = $userId;
$product->product_id = $prod;
for ($i = 1; $i <= 5; $i++) {
if ($request->hasFile('image' . $i)) {
$file = $request->file('image' . $i);
$path = $file->store('public'); // Store the file in the 'images' directory
// Save the file path to the corresponding column
$product->{'image' . $i} = $path;
}
}
$product->save();
After i upload it on laravel storage i want to get a source url online to use it
@Friedrich You get the URL using the aptly-named url method on the Storage facade:
$url = Storage::disk('public')->url($path);
@martinbean this is possible but it resturns
127.0.0.1:800/storage/images/my-image.jpg
i want to have is
https://example.com/storage/images/my-image.jpg
@Friedrich when your request is received by example.com then it will be that in the url. Dont save the url in the database as it limits your ability to publish the site under any domain
If the generated url works file when you visit with the directly generated URL, it means the problem of not showing in shopify is caused by disabled features on your server.
Be sure your host did not disable hotlinking.
<img src="public/3fesIcD8TxXwq8SyeZuZXkOuWbdck8fxyqQL6sPU.png" alt="test">
Guys @sergiu17 @martinbean @christogonus
this is my code at shopify i want to change it to the online source image to able to acces it on shopify page take note i inserting this html at page content of shopify
@Friedrich construct the url using the app.url config element
@Snapey how ?
@Friedrich Well hard to say, because this is clearly wrong
<img src="public/3fesIcD8TxXwq8SyeZuZXkOuWbdck8fxyqQL6sPU.png" alt="test">
public should never appear in any URLs or asset paths.
if the file was in storage/images/3fesIcD8TxXwq8SyeZuZXkOuWbdck8fxyqQL6sPU.png then it could be like
img src="{{ config('app.url') }}/{{$image->url }}">
etc, depending on what you have in the database
@Friedrich I think the problem is that you are confusing the problem of HTML with laravel.
Could you please confirm that this laravel installation is online?
If you do for instance have the laravel app on https://friedrich.shop, then after uploading the product images, try to view the images directly on the browser from https://friedrich.shop/public/3fesIcD8TxXwq8SyeZuZXkOuWbdck8fxyqQL6sPU.png
If the link correctly opens the image, good, then use the html for image should look like
<img src="https://friedrich.shop/public/3fesIcD8TxXwq8SyeZuZXkOuWbdck8fxyqQL6sPU.png" alt="test">
If this doesn't work, then
- ensure that you ran the "php artisan storage:link"
- share the link to your working website (where you have these product images uploaded and working)
can't get it
Please or to participate in this conversation.