DWQA QuestionsCategory: LaravelHow to use inner join in laravel using ORM eloquent ?
asked 6 years ago

Solution :
using whereHas you can use inner join in laravel. let see example :
public function index()
      $user_id   = 42; 
        $data = User::whereHas(‘corporateProfile’,
            function($query) use ($user_id) {
                $query->where(‘user_id’, $user_id); 
note :
suppose you have User model in you have writen method
    public function corporateProfile()
        return $this->hasOne(‘Modules\Admin\Models\CorporateProfile’,’userID’,’userID’);
here you are creating the relation between user and CorporateProfile table. its means User hasOne record in CorporateProfile table. 
whereHas method will return The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables.
with respect to user_id=42.