Laravel: @foreach 不渲染内容
Laravel: @foreach does not render content within
我正在创建一个简单的@foreach,但由于某种原因它被完全忽略了。我确保数据存在。我 var_dumped 在控制器和视图中都存在,变量确实存在。
控制器代码:
public function create(Request $request)
{
$dawrat = Dawra::all();
$ainshams = University::where('name', '=', 'عين شمس')->first();
$faculties = Faculty::where('university_id', '=', $ainshams->id);
return view('createDawra', ['faculties' => $faculties]);
}
我的看法:
<div class="btn-group" data-toggle="buttons">
@foreach ( $faculties as $faculty)
<label class="btn btn-danger " id="collg1">
<input type="checkbox" autocomplete="off">{{ $faculty->name }}
</label>
@endforeach
</div>
尝试添加 ->get()
:
$faculties = Faculty::where('university_id', '=', $ainshams->id)->get()
来自 Laravel Eloquent Retrieving Models Docs:
Since each Eloquent model serves as a query builder, you may also add constraints to queries, and then use the get method to retrieve the results
我正在创建一个简单的@foreach,但由于某种原因它被完全忽略了。我确保数据存在。我 var_dumped 在控制器和视图中都存在,变量确实存在。
控制器代码:
public function create(Request $request)
{
$dawrat = Dawra::all();
$ainshams = University::where('name', '=', 'عين شمس')->first();
$faculties = Faculty::where('university_id', '=', $ainshams->id);
return view('createDawra', ['faculties' => $faculties]);
}
我的看法:
<div class="btn-group" data-toggle="buttons">
@foreach ( $faculties as $faculty)
<label class="btn btn-danger " id="collg1">
<input type="checkbox" autocomplete="off">{{ $faculty->name }}
</label>
@endforeach
</div>
尝试添加 ->get()
:
$faculties = Faculty::where('university_id', '=', $ainshams->id)->get()
来自 Laravel Eloquent Retrieving Models Docs:
Since each Eloquent model serves as a query builder, you may also add constraints to queries, and then use the get method to retrieve the results