2021年1月28日星期四

Laravel eloquent returning wrong data

I have conditional data and it ignores that conditions while returning data:

Works fine

$orders = Order::where('user_id', $user->id)->with(['customer', 'laundry', 'driver', 'driver.user', 'progresses' => function($p){    $p->orderby('created_at', 'asc');  }, 'progresses.progress', 'services'])->get();  

Return wrong data

$orders = Order::where('user_id', $user->id)->with(['customer', 'laundry', 'driver', 'driver.user', 'progresses' => function($p){                  $p->orderby('created_at', 'asc');              }, 'progresses.progress', 'services'])              ->where('id', 'like', '%'.$this->search.'%')              ->orWhere('transport', 'like', '%'.$this->search.'%')              ->orWhere('amount', 'like', '%'.$this->search.'%')              ->orWhere('weight', 'like', '%'.$this->search.'%')              ->orWhere('total', 'like', '%'.$this->search.'%')              ->paginate(10);  

Issue

The second query return all orders and ignores where('user_id', '=', $user->id).

Question

  1. why it ignore where('user_id', '=', $user->id)
  2. How to fix it?
https://stackoverflow.com/questions/65948826/laravel-eloquent-returning-wrong-data January 29, 2021 at 12:32PM

没有评论:

发表评论