jeudi 24 mai 2018

select rows in laravel query

I have two tables request and status_tracker.request table has request_id,approver_id ,status_id fields and status_tracker has request_id,status_before,changed_by,status_after fields.Every request is reviewed and status is changed to 17/20.I want to fetch the record which is reviewed(status=17) and approver_id =1866 in asset_request table and fetch the record which is changed_by '1877' in status_tracker table.

I want to get the records 001(status.tracker.changed_by='1866'), 002(approver_id=1866 and status_tracker.status_after='17'), 004((status.tracker.changed_by='1866')).

request table 
request_id approver_id  status_id requestor
001          11              18    301
002          1866            17    113
003          115             17    159
004          112             19    163
005          1866            1     172
006          1866            20    172  

status_tracker
request_id  status_before   status_after changed_by
  001           null           1            301
  001            1             17          1687
  001            17             8          1724
  001            8             18          1866   
  002           null            2           113
  002            2             17          1687 
  003            null           1           159
  003            1             17          1687
  004            null          1            163
  004            1             17          1687
  004            17             8          1724
  004            8              19         1866     
  005            null           1          172 
  006            null           1          172
  006            1              20         1687    

I have tried as

$users = DB::table('asset_status_tracker')
->leftJoin('asset_request', 'asset_status_tracker.request_id', '=','asset_request.request_id')
->where('asset_status_tracker.status_before','!=',null)
->orwhere('asset_status_tracker.changed_by','=',$approver_id)
->orwhere('asset_request.approver_id','=',$approver_id)
->where('asset_status_tracker.status_after','=','17')->get();

now I get all reviewed records 001,002,003,004,005.What I did worng



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire