我正在尝试运行以下"Results()"查询,并在我的视图中得到以下与foreach循环相关的错误:
public function index()
{
//show view of homepage
return View::make('index');
}
public function results()
{
$query = DB::table('Unions'); // Get the table before applying the where clauses
if (Request::get('Affilation')) {
$Affilation = Input::get('Affilation');
if ($Affilation != null) {
$query = $query->where('Affilation', $Affilation);
}
}
if (Request::get('Office_State')) {
$Office_State = Input::get('Office_State');
if ($Office_State != null) {
$query = $query->where('Office_State', $Office_State);
}
}
if (Request::has('Local_Name')) {
$Local_Name = Input::get('Local_Name');
if ($Local_Name != null) {
$query = $query->where('Local_Name', $Local_Name);
}
}
$results = $query->get(); // Calling get() will execute the query, so it must be last to be called
//show results from union search
return View::make('results')->with('union', $results);
}
public function profile($Local_Name)
{
$union = Union::whereLocal_name($Local_Name)->first();
//show individual union profile
return View::make('profile', ['union' => $union]);
}
这是一个大卡盘的错误:
〔2015-02-28 15:21:48〕生产。错误:异常"ErrorException"中带有消息"未定义的变量:联合"C: ''examplep''htdocs''laravel''app''storage''views''828b81503d4e5a41a8d04770b175c57d:44
堆栈跟踪:
#0 C:'xampp'htdocs'laravel'app'storage'views'828b81503d4e5a41a8d04770b175c57d(44): Illuminate'Exception'Handler->handleError(8, 'Undefined varia...', 'C:''xampp''htdocs...', 44, Array)
#1 C:'xampp'htdocs'laravel'bootstrap'compiled.php(9876): include('C:''xampp''htdocs...')
#2 C:'xampp'htdocs'laravel'vendor'laravel'framework'src'Illuminate'View'Engines'CompilerEngine.php(56): Illuminate'View'Engines'PhpEngine->evaluatePath('C:''xampp''htdocs...', Array)
#3 C:'xampp'htdocs'laravel'bootstrap'compiled.php(9754): Illuminate'View'Engines'CompilerEngine->get('C:''xampp''htdocs...', Array)
#4 C:'xampp'htdocs'laravel'bootstrap'compiled.php(9741): Illuminate'View'View->getContents()
#5 C:'xampp'htdocs'laravel'bootstrap'compiled.php(9732): Illuminate'View'View->renderContents()
#6 C:'xampp'htdocs'laravel'bootstrap'compiled.php(10434): Illuminate'View'View->render()
#7 C:'xampp'htdocs'laravel'bootstrap'compiled.php(9964): Illuminate'Http'Response->setContent(Object(Illuminate'View'View))
这是参考的视线44:
<?php if($unions->count()): ?>
<?php foreach($unions as $union): ?>
您返回的视图带有:
union
而你正试图预测
unions
尝试return View::make('results')->with('unions', $results);