0

I have a sql query with joins is

select t.id,t.trip_id,c.containerid,s.shipment_name,s.source_location_name,s.destination_location_name,ss.status_name,st.status_name as status_type from 
(select T.* from(SELECT * FROM tbl_trip_status ORDER BY id DESC) T group by T.trip_id) ts
JOIN tbl_trips t ON t.id=ts.trip_id
JOIN tbl_container c ON c.id=t.container_id 
JOIN tbl_shipment s ON s.id=t.shipment_id 
JOIN tbl_statuses ss ON ss.id=ts.status_id
JOIN tbl_status_types st ON st.id=ss.status_type
where t.status=1 and t.user_id in (1,2,3,4,5,6,14)  
ORDER BY `t`.`trip_id` ASC

I need this query in eloquent mode while am trying to call paginate() with this raw query, it showing

call to membered function paginate() on array

2 Answers 2

1

Thanks to all I found one solution in eloquent query,i.e.,

DB::table('tbl_trips as t')->select('t.id','t.trip_id','c.containerid','s.shipment_name','s.source_location_name','s.destination_location_name','ss.status_name','st.status_name as status_type')
                    ->join(DB::raw('(select T.* from(SELECT * FROM tbl_trip_status ORDER BY id DESC) T group by T.trip_id) ts'),'ts.trip_id', '=', 't.id')
                    ->join('tbl_container as c', 'c.id', '=', 't.container_id')
                    ->join('tbl_shipment as s', 's.id', '=', 't.shipment_id')
                    ->join('tbl_statuses as ss', 'ss.id', '=', 'ts.status_id')
                    ->join('tbl_status_types as st', 'st.id', '=', 'ss.status_type')
                    ->where('t.status','=',"1")
                    ->where('t.id', '=', 'ts.trip_id')
                    ->whereIn('t.user_id',$subusrs)
                    ->paginate(10);

Thats all..

Sign up to request clarification or add additional context in comments.

1 Comment

you should consider accepting your answer since you found the solution.
0

I think the issue is, after getting the data from your query, you have converted that Std Class Object to an array that's why the error you are getting.

Try this:

$data = DB::select(DB::raw('your query'));

here $data is an Std Class Object on which you can call the paginate functions.

Reference

1 Comment

here also paginate(10) function showing the same call to the membered function error

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.