I have also used \ or
/ but not effective.
Blade
<img src="{{ public_path('images\about.jpg') }}">
PATH
-public
-images
-about.jpg
Using inspect element the link looks fine:
<img src="C:\xampp\htdocs\acc\public\images\about.jpg">
The asset() function is usually used to access the files in public directory of Laravel Application:
<img src="{{ asset('images/about.jpg') }}" alt="some description here">
The public_path() function returns the absolute path for a file which doesn't apply in this case.
Related
I'm new to Laravel, but why the hell is this not working?
<img src='../img/netflix_logo.png' />
I've tried using php artisan storage:link and it said The [C:\xampp\htdocs\laravel-crud\public\storage] link has been connected to [C:\xampp\htdocs\laravel-crud\storage\app/public]. The links have been created. but the image is still not displaying in my .blade page..
If you image is in storage/img then
<img src="{{ url('storage/img/netflix_logo.png') }}" alt="" title="" />
If you image is in public/img folder then
<img src="{{ URL::to('/') }}/img/netflix_logo.png" alt="" title="" />
You probably need to use the "asset" helper from laravel/blade:
asset('/path/of/your/image')
It's the common way to call a static file from public folder (including storage if you already linked it)
I am trying to add images so I can see it on my views. I put the folder img inside the public folder and this is the code I am trying to see.
<?php $image = public_path() . './img/logo.png'; // destination path ?>
<h1>Royal <img src="{{$image}}"> Dice</h1>
All I get is this error in the console: Not allowed to load local resource.
I am learning Laravel but I think that this should be easy to solve. Thank you everyone!
Following should work:
<h1>Royal <img src="{{ asset('img/logo.png' }}"> Dice</h1>
You can find more about the asset helper in the laravel documentation: https://laravel.com/docs/8.x/helpers#method-asset
wite like this <h1>Royal <img src="{{ URL::to($image) }}"> Dice</h1>
or
<h1>Royal <img src="{{ asset($image) }}"> Dice</h1>
I try to access an image that is in following location:
storage/app/public/uploads/myImageIsHere.jpeg
I have tried all stack overflow options, public_path, Storage::url, creating a symlink link and thousands others.
Can someone explain me how to access this image in my .blade file ??
<img src="{{ Storage::url("app/sponsors/8R4HnbOzDdUilnSaZSRj9VzmeI7oKI9JrCWe3rgY.jpeg") }}">
GET http://127.0.0.1:8000/storage/app/sponsors/8R4HnbOzDdUilnSaZSRj9VzmeI7oKI9JrCWe3rgY.jpeg 404 (Not Found)
And this returns a correct path according to my img src path.
Thanks a lot!
Did you try ,
Storage::get("app/public/uploads/myImageIsHere.jpeg");
https://laravel.com/docs/5.8/filesystem
use this instead
<img src="{{ URL::to("/images/abc.jpg") }}">
this will return an image namely abc.jpg inside "public/images" folder.
Run php artisan storage:link to create a symlink to your public storage disk. After that you can access your image like that:
<img src="{{ 'storage/uploads/8R4HnbOzDdUilnSaZSRj9VzmeI7oKI9JrCWe3rgY.jpeg' }}">
The Symfony's mailer documentation says one can embed an image easily:
<img
src="{{ email.image('#images/logo.png') }}"
alt="Logo">
However I have all my assets built by Webpack & Encore. I use the asset manifest file as well, because every asset has a chunkhash in its name.
How to embed an image using Twig in this case? I tried:
<img
src="{{ email.image(asset('build/images/logo.png')) }}"
alt="Logo">
But this doesn't work. I end up with an exception that "a template is missing". This works well of course if I use an image from a static location.
As documentation says: define a Twig namespace that points to whatever directory your images are stored in, for example:
# config/packages/twig.yaml
twig:
paths:
# point this wherever your images live
public/build/: build
next, in your email template:
{# '#build/' refers to the Twig namespace defined earlier #}
<img src="{{ email.image('#build/logo.png') }}" alt="Logo">
<img src="{{ email.image('#build/subdir/logo.png') }}" alt="Logo">
this will not work if the constructed image has some random suffix, e.g. when .enableVersioning() is defined in webpack.config.js config file.
If you have enabled the versioning strategy, you can do the following:
# config/packages/twig.yaml
twig:
paths:
public/: public
and build the template name using the string concat operator ~:
{# '#public' refers to the Twig namespace defined earlier #}
<img src="{{ email.image('#public' ~ asset('build/logo.png')) }}" alt="Logo">
There are two ways to get an image in your mail. First is an embedded image and second is just a link to an image somewhere on the net. If you want to embed an image you will have to attach the image to your mail:
$attachment = Swift_Image::newInstance($data, $filename, $mimeType)
->setDisposition('inline');
$cid = $message->embed($attachment); // Generates "cid:something"
Important is to show your image like this:
<img src="cid:something" ... />
So you have to render your template like this:
$twig->render('email/email.html.twig', [
'cid' => $cid,
...
]);
and in your twig template:
<img src="{{ cid }}" ... />
I am using Laravel to build a Events management system. Users can upload images to be displayed with their event. I have the img tag working on my index.blade.php and assumed I could use the same code on my show.blade.php page, it seems not.
I have the image stored in public/images and I am aware I should use storage for this but I am still learning basics so found this easier for now.
<img style="width:100%" src="images/{{$event->image}}">
As #Frank Ayyaz said you can use a backslash to solve this another Laravel-way is using public_path method which returns the fully qualified path to the public directory.
so you can do something like:
<img style="width:100%" src="{{ public_path('images/'.$event->image) }}">
Please use asset() method. The asset() method is used to include CSS/JavaScript/images files, you can use it as:
{{ URL::asset('images/'.$event->image) }}
<img style="width:100%" src="{{ URL::asset('images/'.$event->image) }}">
You can also use this function for CSS and js.
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
<script src="{{ asset('js/custom.js') }}"></script>
For detail please see this article:
https://medium.com/#zwacky/laravels-url-to-vs-url-asset-fd427ed6f7ef
I suggest Not to use URL::asset but only asset method because sometime URL may cause Problem while showing the image...and use dd() function and check whether u are getting the path i.e Public_path , storage_path() or the custom like the image are stored in public directory..
You may use asset() method of Laravel and use any Prefix whatever you like..
Example:
For static
<img src="{!! asset('assets/images/cams/cam-01.png') !!}" class="img-fluid"
alt="Card image cap">
For Dynamic
<img src="{!! $settings->aws_url.$performer->coverimage !!}" class="img-fluid" alt="Card image cap">
when u use js or css or images u should use {{asset('path')}} to get the resource, it has noting to do with the blade u use, but the resources path.