Many to many where_in syntax for Laravel Eloquent ORM -


i'm struggling make join query using laravel's eloquent orm

i have 2 classes have many many relationship

class type extends eloquent {     public function activities()     {         return $this->has_many_and_belongs_to('activity');     } } class activity extends eloquent {     public function types()     {         return $this->has_many_and_belongs_to('type');     } } 

in database have types, activities, , activities_types tables

i'm trying recreate following sql query

select . *  activities join activities_types @ on a.id = at.activities_id at.type_id in ( 1, 2, 4 )  group a.id 

i haven't grasped orm syntax. i've tried

$activities = activity::types().where_in("id", $types)->get();

but error "non-static method activity::types() should not called statically, assuming $this incompatible context"

thanks pointers

relationships not defined static method. therefore can't use them ::type(). additionally, relationships doesn't give want exactly. because interested in activities column, can this:

$activities = type::where_in("id", $types)->get()->activites()->group_by('id')->get(); 

on other hand, think can handle using join:

$activites = activity::select('activities.*')->join('activities_types','activities.id','=','activities_types.activities_id')->where_in('activities_types.type_id',$types)->group_by('activities.id')->get(); 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -