【问题标题】:Pass a variable from blade to route and from there to another route将变量从刀片传递到路由并从那里传递到另一条路由
【发布时间】:2015-03-02 23:52:38
【问题描述】:

我知道肯定有比我想象的更简单的方法,所以我要在这里问。

我想从这里通过$exam->id(当你点击开始测试时)

@foreach($category->exams as $exam)
    <tr>
        <td>{{$exam->id}}</td>
        <td>{{$exam->title}}</td>
        <td>od {{$exam->start_date}} do {{$exam->end_date}}</td>
        <td class="center"><span class="badge">{{$exam->number_of_points}}</span></td>
        <td class="center"><a href="#"><i class="fa fa-arrow-circle-right"></i> Start test</a></td>
    </tr>
@endforeach()

这应该使用这个路由并传递那个变量

 Route::get('exam','ExamController@create'); // this is where i dont know how to set route to pass to another one

考官

 public function create() {

    return View::make('exam.index');
}

最后,当用户点击提交时,它会将 $exam_id 发送到 ajax 以显示该考试

{{ Form::open(['data-remote', 'method' => 'GET', 'route' => ['exam_data',$exam_id]]) }}
    <div class="exam-name">
    </div>

    <div class="form-group exam">   
        Click Start to start the test!
   </div>

    <div class="form-group">

        {{ Form::submit('Start', ['class' => 'btn btn-default','id'=>'btn-next-question', 'data-confirm']) }}

   </div>

 {{Form::close()}}

提交按钮的路由

Route::get('exam/{id}',['as' => 'exam_data', 'uses' => 'ExamController@getExambyNumber']);

当我在表格上输入随机考试 ID 号(例如 1 而不是 $exam_id)时,一切正常,我只是不知道如何通过它。任何帮助表示赞赏。

【问题讨论】:

  • 在会话中存储信息。然后它将适用于所有请求。
  • 好主意,会试试的

标签: laravel blade laravel-routing


【解决方案1】:

我首先弄清楚我所做的是更改 Start Test 以将数组传递给 Route

 <td class="center"><a href="{{ URL::route('exam_id', array('id'=>$exam->id)) }}"><i   class="fa fa-arrow-circle-right"></i> Start Test</a></td>

考试路线

Route::get('exam',['as' => 'exam_id', 'uses' => 'ExamController@create']);

在控制器中看起来像

public function create()
{

   $exam_id = Input::get('id');
   return View::make('exam.index', array('exam_id' => $exam_id));
}

其余的代码都是一样的。

【讨论】:

    猜你喜欢
    • 2018-04-02
    • 2019-09-22
    • 2020-11-26
    • 2014-08-23
    • 2019-12-30
    • 2022-01-01
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多