我试图运行以下"结果()"在我的视图中查询并获取与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] production.ERROR:exception' ErrorException' 与消息'未定义的变量:联盟'在 C:\ XAMPP \ htdocs中\ laravel \应用\存储\视图\ 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): ?>
答案 0 :(得分:0)
您将返回一个视图:
union
你正试图预言
unions
尝试return View::make('results')->with('unions', $results);