Hazem Alrfati
Hazem Alrfati

Reputation: 47

Laravel 8 - How to write statement with paginate instead with get

I use Alias name of column because I have two columns in different tables with the same name, when retrieve them one column will override another column

DB::table('trip_user')
        ->join('trips', 'trips.id', '=', 'trip_id')
        ->join('users', 'users.id', '=', 'user_id')
        ->where('guide_id','=',$id)
        ->get(['*','trips.name As tirp_name','trip_user.id As reservation_id'])

How can I write it with paginate?

Upvotes: 0

Views: 39

Answers (1)

Marwane Ezzaze
Marwane Ezzaze

Reputation: 1057

Try it this way:

$result = DB::table('trip_user')
        ->join('trips', 'trips.id', '=', 'trip_id')
        ->join('users', 'users.id', '=', 'user_id')
        ->where('guide_id','=',$id)
        ->paginate(100, ['*','trips.name As tirp_name','trip_user.id As reservation_id']);

Upvotes: 1

Related Questions