Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to get only the first 3 records of a table in laravel

//routesweb.php
Route::get('/get-10-records', [HomeController::class, 'getRecords']);

//Create controller if not exists using
php artisan make:controller HomeController

//appHttpControllersHomeController.php
use AppModelsUser;

class HomeController extends Controller
{
    public function getRecords(){
        $users = User::select('*')->take(10)->get();
        return response()->json($users);
    }
}
Source by w3codegenerator.com #
 
PREVIOUS NEXT
Tagged: #records #table #laravel
ADD COMMENT
Topic
Name
1+8 =