我是从 Laravel 开始的初学者。我试图展示在这个网站上提出的问题。
这是控制器页面:
public function show($id)
{
//Use the model to get 1 record from the database
$question = $Question::findOrFail($id);
//show the view and pass the record to the view
return view('questions.show')->with('question', $question);
}
我已在文件顶部包含:
use App\Question;
这是我的刀片页面:
@section('content')
<div class="container">
<h1> {{ $question->title }} </h1>
<p class="lead">
{{ $question->description }}
</p>
<hr />
</div>
@endsection
在模型中我没有定义任何东西,因为我不需要指定任何特殊规则。最后是路线:
Route::resource('questions', 'QuestionController');
我收到错误“ErrorException Undefined Variable: Question”,据说错误是:
$question = $Question::findOrFail($id);
我期待着你的意见。
亲切的问候。