0

I have a ProcessHistory and Person model I need a eloquent code for relation with multiple condition. Conditions: 1. oindex = oindex 2. pat_id = pat_id

I want a eloquent code to get result of the following sql code

select * from tbl_process_history as s join tbl_persons as p on (s.oindex = p.oindex and s.pat_id = p.pat_id)

I need to get all the persons having same oindex and pat_id. I have tried with below eloquent code where I can apply condition inside of relation 'own'. Here I can apply only for as static value.

ProcessHistory::with(['own'=>function($query){
                return $query->where('pat_id','');
            }])->get();

I need a condition inside of relation where I can match pat_id of process history model with persons model.

2 Answers2

1

I just found that I was actually searching for relationship with composite key but this feature is not provided in laravel. It can be solved by using https://github.com/topclaudy/compoships package.

0

ProcessHistory::with(['own'=>function($query) use ($param){ return $query->where('pat_id',$param); }])->get();

Dawood Akram
  • 9
  • 1
  • 2