Skip first n record and display rest records in laravel view

Updated at 06-Sep-2021, By samar

Skip first n record and display rest records in laravel view

In this tutorial, we will try to find the solution to "Skip first n record and display rest records in laravel view" through programming.

You can skip first n records and display rest records in laravel view using skip() method. You have to pass the amount of number to skip() method that you want to skip and after that you can display in view file using foreach in laravel
  • Skip first 3 records from user collection and display rest in view using foreach in laravel

    @foreach($users->skip(3) as $key => $user)
        {{ $user->name }}
    @endforeach
    

    It will display all the records from user collection except the first three in laravel view file. To display data in view file you have to get the users record and return to view file.

    Get the users records and return to view file to display it. 

    $users = User::select('*')->paginate(10);

    return view('home')->with(['users'=>$users]); 

Back to code snippet queries related laravel