如何查看每条记录?每条记录都是一个链接,如果点击,它应该在查看页面上显示该记录。
Route::get('question/{$id}', array('as'=>'question', 'uses'=>'QuestionController@show'));
这是显示方法:
public function show($id = null)
{
return view('questions.view')
->with('title', 'Make it Snappy - Question')
->with('question', Question::find($id))
->with('users', Auth::user()->username);
}
这是 index.blade.php 页面
@extends('layouts.default')
@section('content')
<h1>Ask a Question</h1>
@if(Auth::check())
@if($errors->has())
<p>The following errors have occured:</p>
<ul id="form-errors">
{!! $errors->first('ask
', '<li>:message</li>') !!}
</ul>
@endif
{!! Form::open(array('url' => 'ask', 'method' => 'post')) !!}
{!! Form::token() !!}
<p>
{!! Form::label('question', 'Question') !!}<br />
{!! Form::text('question', Input::old('question')) !!} <br />
{!! Form::submit('Ask a Question') !!}
</p>
{!! Form::close() !!}
@else
<p>Please login to ask a question.</p>
@endif
<div id="questions">
<h2>Unsolved Questions</h2>
@if(!count($questions) > 0)
<p>No questions have been asked</p>
@else
<ul>
@foreach($questions as $question)
<li>{!! Html::linkRoute('question', str_limit($question->questions, 35), $question->id) !!} by
@if(count($users) > 0)
@foreach($users as $user)
@if($user->id === $question->userid)
{!! ucfirst($user->username) !!}
@endif
@endforeach
@endif
</li>
@endforeach
</ul>
{!! $questions->render() !!}
@endif
</div>
@stop
我想要的是,当我单击任何问题时,它应该显示在视图页面上。我感谢您的支持。