lara123's avatar

How to use pagination with offset and limit in laravel5.3 using ORM ?

$all_data1 = Infoall::with('location','user')->where('user_id','=',$user->id) ->whereBetween('photos.image_date_time',array($start_date,$end_date)) ->orderBy('photos.image_date_time', 'DESC')->get();

$all_data = $all_data1->toArray(); // For all objects into array colletion .

Infoall my model name.

0 likes
3 replies
sherwinmdev's avatar

@subodh instead of get() use paginate()

$all_data1 = Infoall::with('location','user')->where('user_id','=',$user->id) ->whereBetween('photos.image_date_time',array($start_date,$end_date)) ->orderBy('photos.image_date_time', 'DESC')->paginate();

in your view

{{ $all_data1->links() }}

@foreach ($all_data1 as $data)
    {{ $data->column_name; }}
@endforeach 

you can pass the per page value as an argument in paginate(). for instance, if you want 10 per page, paginate(10). the default is 15 i believe.

lara123's avatar

can we use this.

$all_data1 = Infoall::with('location','user')->where('user_id','=',$user->id)->whereBetween('photos.image_date_time',array($start_date,$end_date))->orderBy('photos.image_date_time', 'DESC')->take(10)->skip(0)->get();

take = limit skip - offset

lara123's avatar

$get_state_dentist = State::where('state_name','=',trim($state_name)) ->select(\DB::raw('dentist_table.id,dentist_table.Year_Founded,dentist_table.Coordinates,dentist_table.ZIP_Code,dentist_table.Contact_Name,dentist_table.State_Code,dentist_table.Business_Name,Reviews.status,dentist_table.Coordinates,dentist_table.City,dentist_table.Phone,dentist_table.Address,State.state_name,State.state_code,Reviews.dentist_id,Reviews.service,Reviews.availability,Reviews.location,Reviews.affordability')) ->Join('dentist_table', 'State.state_code', '=', 'dentist_table.State_Code') ->where('dentist_table.Address','!=','') ->where('dentist_table.Contact_Name','!=','') ->where('dentist_table.Coordinates','!=','') ->where('dentist_table.Phone','!=','') ->where('dentist_table.Phone','!=',0) ->leftJoin('Reviews', 'Reviews.dentist_id', '=', 'dentist_table.id') ->take(15) ->groupBy('dentist_table.id') ->get()

    ->toArray();

Please or to participate in this conversation.