Laravel 8 Eloquent limit() Query
In this tutorial, we will read Laravel 8 Eloquent limit() Query. I would like to share with you information about the Limit query in the Laravel application. Laravel Limit and offset are used to paginate records or get the number of records from the database table from an offset. the limit() to results returned from the query. Most of the 10 records are in all tables so I will show you get only 4 records to the students’ table. And use the offset and limit query in Laravel 8 for it. In this example, I will see how to use the limit and offset in the Laravel application.
Example 1
<?php
namespace App\Http\Controllers;
use DB;
class UserController extends Controller
{
public function index()
{
$students = DB::table('students')->limit(4)->get();
dd($students);
}
}
Output
Example 2
<?php
namespace App\Http\Controllers;
use App\Models\Student;
class UserController extends Controller
{
public function index()
{
$users = Student::limit(4)->get();
dd($users);
}
}