1

Business Model

   public function groupTag()
   {
        return $this->belongsTo('GroupTag');
   }

Group Tag Model

    public function tag()
    {
        return $this-    >belongsToMany('Tag','group_tag_tags','group_tag_id','tag_id')
        ->withTimestamps();
    }

    public function business()
    {
        return $this->hasOne('Business');
    }

Tag Model

   public function groupTag()
    {
        return $this->belongsToMany('Group','group_tag_tags','group_tag_id','tag_id')->withTimestamps();
    }

Now how do i run this query into a laravel project

SELECT * FROMbusinesses` as b, group_tags as gt, group_tag_tags as gtt, tags as t where b.group_tag_id = gt.id and gt.id = gtt.group_tag_id and gtt.tag_id = t.id and t.id = 36 or b.name like '%a%' and b.city_id = 5 group by b.id'

1 Answer 1

1
DB::table('businesses')
        ->join('group_tags','group_tags.id','=','businesses.group_tag_id')
        ->join('group_tag_tags','group_tag_tags.group_tag_id','=','group_tags.id')
        ->join('tags','tags.id','=','group_tag_tags.tag_id')
        ->where('tags.id',"=",36)
        ->where('b.name',"LIKE",'%a%')
        ->where('b.city_id',"=",5)
        ->select('businesses.id','businesses.name','businesses.description','businesses.image')
        ->groupBy('businesses.id')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.