mardi 27 juin 2017

How to take matching data from collections using laravel and mongo?

I have two collections bookings and users. In bookings collection I have a field user. It is related to users._id.

I have a booking listing page. In this listing page data from bookings and users are showing.

In this listing page I have a text box to search invoice_number, payment_type, txid and usrEmail. I have written query to search invoice_number, payment_type, txid and it is working but I am stuck on usrEmail section. How can I combine with users and write search query to search usrEmail?

I am using laravel and mongodb. I am following "http://ift.tt/1qxFWF0"

bookings

_id, user, invoice_number, payment_type, txid

users

_id, firstName, SecondName, usrEmail

Search Query

$bookings = Booking::select('_id', 'invoice_number', 'temp_user_id', 'user', 'checkin_from', 'reserve_to', 'beds', 'dormitory', 'sleeps', 'status', 'payment_status', 'payment_type', 'total_prepayment_amount', 'cabinname', 'reference_no', 'clubmember', 'bookingdate', 'txid')
                ->where('is_delete', 0)
                ->where(function($query) use ($search) { /* That's the closure */
                    $query->where('invoice_number', 'like', "%{$search}%")
                        ->orWhere('payment_type', 'like', "%{$search}%")
                        ->orWhere('txid', 'like', "%{$search}%");
                })
                ->skip($start)
                ->take($limit)
                ->orderBy($order, $dir)
                ->get();

App\Booking

public function user()
    {
        return $this->hasOne('App\Userlist', 'user', '_id');
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire