Php 将查询对象输出到视图中

Php 将查询对象输出到视图中,php,object,laravel,view,laravel-5,Php,Object,Laravel,View,Laravel 5,我的搜索功能没有返回我期望的结果 如何输出查询对象以查看db查询返回的内容 public function search() { //Save requests to variables $price = Helper::explodeString(Request::get('price')); $texts = Helper::explodeString(Request::get('texts')); $minutes = Helper::explodeString(Request::get(

我的搜索功能没有返回我期望的结果

如何输出查询对象以查看db查询返回的内容

public function search()
{
//Save requests to variables
$price = Helper::explodeString(Request::get('price'));
$texts = Helper::explodeString(Request::get('texts'));
$minutes = Helper::explodeString(Request::get('minutes'));
$data = Helper::explodeString(Request::get('data'));
$contract = Request::get('contract');
$phone_option = Request::get('phone-option');
//get all selected carriers
$carriers = array();
foreach(Carrier::all() as $carrier){
    if(Request::has($carrier->name)){
        $carriers[] = $carrier->id;
    }
}
// build query
$query = Plan::whereBetween('price', $price)
            ->whereBetween('text', $texts)
            ->whereBetween('minutes', $minutes)
            ->whereBetween('data', $data)
            ->whereIn('carrier', $carriers)
            ->where('contract', $contract)
            ->where('phone_inlcuded', $phone_option);

return view('planresults')->with('plans', $query);
}
然后我尝试将对象输出到我的视图中,如下所示

@foreach($plans as $plan)

<div class="panel price">

    <div class="panel-heading arrow_box text-center">
        <h3>{{$plan->Carrier->name}}</h3>
        <h3>{{$plan->name}}</h3>
    </div>
    <div class="panel-body text-center">
        <p class="lead" style="font-size:40px"><strong>${{$plan->price}} / month</strong></p>
    </div>
    <ul class="list-group list-group-flush text-center">
        <li class="list-group-item">{{$plan->Carrier->name}}</li>
        <li class="list-group-item">{{$plan->contract}} Month term contract</li>
        @if($plan->phone_included == 0)
            <li class="list-group-item">No phone included</li>
        @else
            <li class="list-group-item">Phone option included</li>
        @endif
    </ul>
    <div class="panel-footer">
        <a class="btn btn-lg btn-block btn-success" href="{{$plan->url}}">BUY NOW!</a>
    </div>
</div>
<!-- /PRICE ITEM -->

@endforeach
@foreach($plan作为$plan)
{{$plan->Carrier->name}
{{$plan->name}

${{{$plan->price}}/月

  • {{$plan->Carrier->name}
  • {{{$plan->contract}月期合同
  • @如果($plan->phone_include==0)
  • 不包括电话
  • @否则 包括电话选项 @恩迪夫
@endforeach

没有结果显示在我的视图中,所以我假设我的对象是空的。。。我很困惑,已经在这个问题上纠缠了很久了

您从未在
$query
中执行过查询。阅读:

您需要指定以下选项之一:

  • $query->pull()
  • $query->get()
  • $query->first()

我的查询仍然没有返回预期结果。如何查看发送到数据库的SQL查询?基于它的
$querys=DB::getQueryLog()$最后一次查询=结束($querys)