db:raw的不良结果 [英] Undesired result from db:raw
问题描述
我从SO和Laravel论坛中都得到了一些答案,以汇总结果.但是,我有一个Undefined variable error
,我不确定为什么.
I have taken a few answers from both SO and the Laravel forums to piece together the results. However, I am having an Undefined variable error
and I'm not sure why.
public function getJobs()
{
$query = DB::table('jobs');
if (isset($jcategory))
$query->where('category', '=', $jcategory);
$result = $query->get();
return View::make('jobsearch.search', $result);
}
视图(已缩写为空格)
<form action="{{ action('JobsearchController@getJobs') }}" method="post">
<div class="row">
<div class="large-8 columns">
<input type="text" name="realm" placeholder="Keywords/Skills" />
</div>
<div class="large-4 columns">
<select name="jcategory">
<option value="">Select Category</option>
<option value="jc1">Accounting</option>
...
</select>
</div>
<div class="large-4 columns">
<input type="submit" value="Search" style="width:100%; padding-top: .5rem;
padding-bottom: .5rem;" class="button border-btn" />
</div>
</div>
</form>
@foreach ($result as $job)
<p>{{ $job->id }}</p>
@endforeach
一旦我完成了这个小测试,我将把isset
的其余部分添加到$query
中.我要实现的目标是,视图将加载数据库中的所有作业,并且如果用户更改类别(例如)并提交视图,它将使用查询中反映的更改重新加载页面.
Once I get this little test working I will add the rest of the isset
into the $query
. What I am trying to achieve is that the view will load all jobs in the database and if the user changes the category (for example) and submits the view it will reload the page with the reflected changes in the query.
我目前在视图上出现Undefined variable: result
错误.我已经以不同的方式尝试了foreach
,但是我感觉控制器没有传递任何东西.
I currently get an Undefined variable: result
error on the view. I have tried the foreach
in different ways but I have a feel that the controller isn't passing anything through.
推荐答案
您以错误的方式传递了$result
变量.试试这个:
You passed the $result
variable the wrong way. Try this:
return View::make('jobsearch.search')->with('result', $result);
这篇关于db:raw的不良结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!