dongxia19772008 2015-02-25 05:54
浏览 48
已采纳

Laravel Eager with Where约束

I have 2 methods with eager loading and paginate. but problem is that i have to use where constraint too and i am getting offset 0 error.

public function showAllOrders(){
    $orders = \admin\Order::with('orderfiles','paymentStatus','orderStatus','orderDelivery','flexibleDelivery')->paginate(20);
        return View('admin.all_orders')
            ->with('orders',$orders);
}

public function showAllPaidOrders(){
    $orders = \admin\Order::with(array('orderfiles','orderStatus','orderDelivery','flexibleDelivery','paymentStatus'=>function($query){
        $query->where('status', '=', 'Paid');
    }))->paginate(20);
        return View('admin.all_orders')
            ->with('orders',$orders);
}

showAllOrders working fine but when i am using where constraint with showAllPaidOrders i am getting offset error....

1/2 ErrorException in Collection.php line 837: Undefined offset: 0 2/2 ErrorException in Collection.php line 837: Undefined offset: 0 (View: E:\content\xampp\htdocs\l5esources\views\admin\all_orders.blade.php)

Even if both blade views are same. The only difference is the "Where Constraint"

  • 写回答

2条回答 默认 最新

  • dph23577 2015-03-31 05:37
    关注

    i solved this with using wherehas function

    public function showAllOrdersbySite($domain_id){
        $orders = Order::whereHas('paymentStatus', function ($query) use($domain_id) {
            $query->where("domain_id","=",$domain_id);
    
        })->orderby('tbl_orders.created_at', 'desc')->paginate(20);
            return View('admin.all_orders')
                ->with('orders',$orders);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)