Mohamed ELBAZIGH
Mohamed ELBAZIGH

Reputation: 33

Show the result of a route in blade view (Laravel)

I have a route that return an image, and i want the show the result of this route in a blade view, is there a way to directly call controller action or result of this route directly in the blade view ?

Thanks in advance.

Upvotes: 1

Views: 991

Answers (3)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

You rather don't want to return image in blade. You should create separate controller action, that will return this image and link image src to this route, for example in controller:

public function image()
{ 
    return $img = Image::make('image.jpg')->resize(800, 500)
    ->insert('sub_image.jpg', 'bottom-right', 10, 10) ->response(); 
}

then you create route to this controller action:

Route::get('my-image', 'MyController@image')->name('get-my-image');

and then in your Blade view you should link image src to this action:

<img src="{{ route('get-my-image') }}">

Upvotes: 2

Amit Gupta
Amit Gupta

Reputation: 17658

You can do this by giving the URL in src attribute of <img> tag as:

<img src="{{ route('image.url') }}">

Upvotes: 1

nxu
nxu

Reputation: 2272

Well if it's an image, why don't you use an img tag?

<img src="{{ route('my.image') }}" alt="My Image">

Upvotes: 1

Related Questions