dynamic routing for images in laravel

随声附和 提交于 2019-12-12 02:56:33

问题


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


回答1:


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"



回答2:


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.



来源:https://stackoverflow.com/questions/26319100/dynamic-routing-for-images-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!