Laravel 在 view->with() 上不返回数据
Laravel not returning data on view->with()
我在 return view()->with();
语句中返回数据时遇到了一些问题。
我得到的错误只是一个带有默认 laravel 授权导航栏的空白屏幕。
MySQLtable结构:
编号 |版本 |活跃|鼻涕虫
这是我的代码供您查看。
函数
function index() {
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc');
return view('changelog.index')->with('changelogs', $changelogs);
}
路线(以备不时之需)
Route::get('/release-notes', 'Changelogs\MyController@index');
查看
@foreach($changelogs as $changelog)
<div class="row">
div class="col-md-10 col-md-offset-1">
div class="panel panel-default">
<div class="panel-heading">
<h3><a href="{{ url('/release-notes/'.$changelog->slug) }}">{{ $changelog->version }}</a></h3>
</div>
<div class="panel-body">
{!! $changelog->body !!}
</div>
</div>
</div>
</div>
@endforeach
更改此行:
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc');
收件人:
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc')->get();
希望对您有所帮助。
tl:dr 您需要添加 ->get()
来完成您的 fluent query.
function index() {
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc')->get();
return view('changelog.index')->with('changelogs', $changelogs);
}
奖金 您可以执行的所有方法都可以在 API docs 中找到。我的最爱之一是 echo ->toSql()
这样你就可以检查 SQL 语句。
我在 return view()->with();
语句中返回数据时遇到了一些问题。
我得到的错误只是一个带有默认 laravel 授权导航栏的空白屏幕。
MySQLtable结构:
编号 |版本 |活跃|鼻涕虫
这是我的代码供您查看。
函数
function index() {
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc');
return view('changelog.index')->with('changelogs', $changelogs);
}
路线(以备不时之需)
Route::get('/release-notes', 'Changelogs\MyController@index');
查看
@foreach($changelogs as $changelog)
<div class="row">
div class="col-md-10 col-md-offset-1">
div class="panel panel-default">
<div class="panel-heading">
<h3><a href="{{ url('/release-notes/'.$changelog->slug) }}">{{ $changelog->version }}</a></h3>
</div>
<div class="panel-body">
{!! $changelog->body !!}
</div>
</div>
</div>
</div>
@endforeach
更改此行:
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc');
收件人:
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc')->get();
希望对您有所帮助。
tl:dr 您需要添加 ->get()
来完成您的 fluent query.
function index() {
$changelogs = Changelogs::where('active', '1')->orderBy('created_at', 'desc')->get();
return view('changelog.index')->with('changelogs', $changelogs);
}
奖金 您可以执行的所有方法都可以在 API docs 中找到。我的最爱之一是 echo ->toSql()
这样你就可以检查 SQL 语句。