【发布时间】:2020-10-17 16:45:51
【问题描述】:
我想将我的数据库中的一个变量(在我的例子中称为 $document)添加到我的刀片文件视图中的 URL 资产目录,以使用户能够在网络浏览器。一个例子如下;
// MyController File
// the variable $code is a parameter I'm accepting from the web.php route file for
// the function show() to help process the assignment value of $data['document'] without issues
public function show($code)
{
// NB: I am passing the document as an array list item of $data as below, so I can mention it as
// a variable in the blade view file
// $data['document']
$data['document'] = Auth::user()->documents->where("code", $code)->first();
return view("documents.show", $data);
}
// Blade View File
<div class="my-class" style="background: url({{ URL::asset('assets/storage/' +$document->file_url) }}) no-repeat center top; background-size: cover;">
</div>
【问题讨论】:
标签: laravel variables laravel-5 laravel-blade laravel-7