Home > database >  Laravel: How to exclude first row in table?
Laravel: How to exclude first row in table?

Time:09-26

What should I do if I want to exclude the first row in retrieving the users table?

    public function index()
{
    $users = User::all();
    return view('users.users',['users'=> $users]);
}

CodePudding user response:

if you want to make static you can do this

   public function index()
{
    $users = User::all();
    $first_key = $users->keys()->first();
    $users = $users->forget($first_key);
    return view('users.users',['users'=> $users]);
}

CodePudding user response:

Use the Laravel Collection Skip method: documentation

public function index()
{
    $users = User::all()->skip(1);
    return view('users.users',['users'=> $users]);
}

CodePudding user response:

You may use the skip with get() methods to skip a given number of results in the query:

public function index()
{
    $users = User::get()->skip(1);
    return view('users.users',['users'=> $users]);
}

CodePudding user response:

You can use skip. User::all()->skip(1);

  • Related