【问题标题】:View records on a view page by clicking the links通过单击链接在查看页面上查看记录
【发布时间】:2016-03-11 17:40:34
【问题描述】:

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

 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

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

【问题讨论】:

  • 我想你还没有指定路线?你在使用资源控制器吗
  • 抱歉回复晚了。路线是我在代码顶部指定的。第一行。我做错了吗?
  • 你能告诉我你的网址吗?
  • {!! Form::open(array('url' => 'question', 'method' => 'post')) !!}
  • 这是网址。谢谢。感谢您的关心和支持。

标签: eloquent laravel-5.1 show laravel-blade


【解决方案1】:
 Route::get('question/{$id}', array('as'=>'question', 'uses'=>'QuestionController@show'));

您的路线在您的表单方法发布时接受 get,因此无法找到 get 请求,因此请尝试使其 get

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

试试看

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

【讨论】:

  • 谢谢。表格做两件事。接受问题的输入并显示问题。我将编辑帖子并发布 index.blade.php 的完整代码。所以你提到的那个是用于发布的,它工作正常。该链接用于在查看页面上显示问题。我相信我正在遵循的实现已经改变,因为它是 Laravel 4,它在实现上与我正在使用的最新 Laravel 5.1.* 框架非常不同。
  • 我已经编辑并发布了 index.blade.php 的完整代码
  • 是的,你是对的,但是如果你想让它发生,一个表单可以同时处理 post 和 get发帖希望你理解
  • 对我来说这听起来像是希腊语,因为我是 Laravel 的新手。如果您能对实现的代码 sn-p 提供帮助,我将不胜感激。
  • 你想同时处理 post 和 get from the single form 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-19
  • 1970-01-01
  • 1970-01-01
  • 2021-01-15
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
相关资源
最近更新 更多