2

I have two collections users and clients. I want to use join between this two collections. Use hasMany relations. My eloquent query as follows

$user_list = User::with('clientMaster')
                    ->where('client_status', '=', 1)
                    ->get()
                    ->toArray()

User Model

public function clientMaster()
{
    return $this->hasMany('App\Client', '_id', 'client_name');
}

Now, when I print $user_list output as below. This output comes from users collection

    (
    [0] => Array
        (
            [_id] => 5788bbe97ffbe04a467634e1
            [name] => Abc Pqr
            [email] => abc.pqr@xyz.in
            [client_id] => 57876dcdc83aa906e81371f4
            [client_master] => Array
                (
                )
        )
)

Now I want use join between client and user for fetcing client name on behalf of client._id = users.client_id. I don't know how to use join in laravel eloquent. Please suggest me.

sandip kakade
  • 1,346
  • 5
  • 23
  • 49
  • Mongo is not a relational database. It doesn't have joins. Your query also has no join. `with()` doesn't use joins. – user2094178 Jul 15 '16 at 16:10

0 Answers0