How can i add a condition in contain to paginate in Cakephp3.
This is my code :
$this->paginate = [
'contain' => ['Users', 'AssignDrivers.Users', 'Invoices']
];
$bookings = $this->paginate($this->Bookings);
$this->set(compact('bookings'));
$this->set('_serialize', ['bookings']);
For example Something like this:
$this->paginate($this->bookings)->where(['Bookings.status'=>'pending', 'AssignDrivers.name LIKE'=>'%John%']);
Thank you for help.
Try using a condition inside paginate() method.
$this->paginate = [
'contain' => ['Users', 'AssignDrivers.Users', 'Invoices']
];
$bookings = $this->paginate(
$this->Bookings->find()->where([
'Bookings.status'=>'pending',
'AssignDrivers.name LIKE'=>'%John%'
])
);
$this->set(compact('bookings'));
$this->set('_serialize', ['bookings']);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.