-1

如何查看每条记录?每条记录都是一个链接,如果点击,它应该在查看页面上显示该记录。

 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

返回的错误信息

index.blade.php 页面

我想要的是,当我单击任何问题时,它应该显示在视图页面上。我感谢您的支持。

4

1 回答 1

0
 Route::get('question/{$id}', array('as'=>'question', 'uses'=>'QuestionController@show'));

您的路线接受获取,而您的表单方法已发布,因此无法找到获取请求,因此请尝试使其获取

{!! Form::open(array('url' => 'question', 'method' => 'post')) !!}

试试看

{!! Form::open(array('url' => 'question', 'method' => 'get')) !!}
于 2015-12-07T10:11:31.313 回答