dongmale0656 2014-02-24 23:03 采纳率: 100%
浏览 44
已采纳

来自db:raw的不受欢迎的结果

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.

Controller

public function getJobs()

        {
            $query = DB::table('jobs');

            if (isset($jcategory))
            $query->where('category', '=', $jcategory);

            $result = $query->get();
           return View::make('jobsearch.search', $result);
        }

View (has been abbreviated for space)

<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

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.

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.

  • 写回答

1条回答 默认 最新

  • dsa88885555 2014-02-25 00:02
    关注

    You passed the $result variable the wrong way. Try this:

    return View::make('jobsearch.search')->with('result', $result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算