我无法访问我在laravel 4中从控制器发布的变量
问题描述:
i have laravel application. i posted variable $res in my controller to my view and in the view i have no access to the variable i posted. here is my code:
my route:
Route::get('/pickUpQuestion','createQuizController@showResult');
my controller:
public function showResult()
{
$prio = Input::get('quiz_prio');
$cat = Input::get('quiz_cat');
$les = Input::get('quiz_less');
$rdate = Input::get('date_start');
$res = DB::select("select title from quiz where categories_id='$r2' and lesson_id='$r3' and priority_id='$r1' and date_start='$rdate'");
return View::make('pickUpQuestion')->with('result',$res);
}
and my view:
@extends('layouts.master')
@section('content')
<?php
var_dump($res);
?>
@stop
i take the values in my query from another form in a different view with post method to this view
答
The mistake is with the function with()
The first parameter need to be the name of variable that will be use in view and the second parameter is the value of the first parameter.
The code should look like this
return View::make('pickUpQuestion')->with('res',$res);