Tôi đã tạo ra một helper Asset của riêng tôi.
Đầu tiên tôi xác định các loại tài sản và con đường trong app/config/assets.php
:
return array(
/*
|--------------------------------------------------------------------------
| Assets paths
|--------------------------------------------------------------------------
|
| Location of all application assets, relative to the public folder,
| may be used together with absolute paths or with URLs.
|
*/
'images' => '/storage/images',
'css' => '/assets/css',
'img' => '/assets/img',
'js' => '/assets/js'
);
Sau đó, thực tế Asset
lớp:
class Asset
{
private static function getUrl($type, $file)
{
return URL::to(Config::get('assets.' . $type) . '/' . $file);
}
public static function css($file)
{
return self::getUrl('css', $file);
}
public static function img($file)
{
return self::getUrl('img', $file);
}
public static function js($file)
{
return self::getUrl('js', $file);
}
}
Vì vậy, theo quan điểm của tôi, tôi có thể làm điều này để hiển thị một hình ảnh:
{{ HTML::image(Asset::img('logo.png'), "My logo")) }}
Hoặc như thế này để triển khai tập lệnh Java:
{{ HTML::script(Asset::js('my_script.js')) }}
Nguồn
2014-10-09 19:52:37
Nó làm việc cho tôi! – Kasthuriraajan