Count all and get 10 records after where condition in laravel

You can get the count of all records after the where condition and get the specific number of record (10 records) from the table.

Answers 1
  • Count all and get 10 records after where condition in laravel

    $query = $request->get('query');
    $users = User::where('name','like','%'.$query.'%');
    $usersCount = $users->count();
    $users = $users->select('*')->take(10)->get();
    echo $usersCount;
    print_r($users);
    
    1

    This code snippet will help you to get the count of all filltered data and get only 10 records from filttered data.

  • Back to code snippet queries related laravel