jeudi 29 septembre 2016

code optimization laravel.i want to retrived a avilable group where member not already exist

there is a three table

user,memember,group_member(relation mem_id,group_id) many to many

i have define a relation for group on member model

public function group(){
        return $this->belongsToMany('Model\Group', 'group_member', 'mem_id', 'group_id');
    }

using above relation i can retrieve a member asigned group using

   Model\Member::with('group')->find('member_id')

now i want those group where member is not assigned . i have done using

$arg['ids'] = $member->group->lists('_id');
        $group = Group::where('user_id',$user_id)->whereNotIn('_id',$arg['ids'])->limit($arg['limit'])->offset($arg['offset'])->get();

there is a another option rather then subquery ??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire