sha
sha

Reputation: 157

dynamic routing for images in laravel

I have a big deal with image or some features routing in laravel ... for example I have a dashboard page that has @yield('content') ... in dashboard there are some images like logo.png / background-pattern.png & ... . when I get a url for them for example

src="assets/img/logo.png" 

. it's ok for urls like

Route::get('/reports' ...)

but it doesnt work for

Route::get('/report/crete' ...)

page . for create page I should give a src like

 src="../assets/img/logo.png"

how can I give the url dynamically to images ??

sorry if it's stupid question I'm newbie in laravel . thanks for time

Upvotes: 0

Views: 1708

Answers (2)

Marcin Nabiałek
Marcin Nabiałek

Reputation: 111829

You can use:

asset('assets/img/logo.png')

It will generate the whole url.

Another method is setting base href in head section of your HTML document:

<base href="http://yoururl.com/" />

(with trailing slash at the end)

and use everywhere:

src="assets/img/logo.png"

Upvotes: 1

Jarek Tkaczyk
Jarek Tkaczyk

Reputation: 81157

As a general rule use absolute paths:

src="/assets/whatever"

then it doesn't matter if the url contains 'directory', like /some/roue/here

Using helper asset provided by laravel is also the way of course.

Upvotes: 0

Related Questions