未定义的变量:论坛

时间:2017-12-15 16:57:31

标签: php laravel laravel-5 laravel-4 undefined

未定义的变量给出错误我该怎么办? ForumController:

func testTitleForPCells() {
    let cell = PCell(style: .default, reuseIdentifier: "anything")
    let model = Model(title: "FOO")
    cell.setMyModel(model)
    XCTAssertEqual(cell.titleLabel.text, model.title)
}

路线:

public function index()
{
    $forums = Forum::all();
    return view('forum.index') -> withForum($forums);
}

welcome.blade:

Route::resource('/forum','ForumController');

ErrorException:

@foreach($forums as $forum)
 <div class="col-md-7">{{ $forum->title }}</div> 
     <div class="col-md-5 text-center">
     <span class="label label-warning">پاسخ : ۱۰</span>
     <span class="label label-primary">تشکر : ۱۰</span>
     <span class="label label-success">RaymondDragon</span>
 </div>@endforeach

4 个答案:

答案 0 :(得分:2)

我认为您需要像这样定义论坛变量:

return view('forum.index')->with('forums', $forums);

答案 1 :(得分:1)

return view('forum.index') -> withForums($forums);
// or
return view('forum.index') -> with('forums', $forums);

答案 2 :(得分:1)

return view('forum.index', ['forums' => $forums]);

答案 3 :(得分:0)

return view('forum.index', compact('forums'));

是实现目标的巧妙方法。