i have a paginate table and i get the link like this students/40 and this 40 i insert it into controller to paginate function
@mahmoudadelali Why? That’s literally what a query string is for, and what Laravel does by default.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there , i have a paginate table and i get the link like this students/40 and this 40 i insert it into controller to paginate function , but if i edit the link to string i got ERRor and in debug:false i get 500 server error so i can validate it with PHP - or there's laravel way to validate it ? The Code
public function index(Request $request,int $count = 10)
{
$request->validate([
'count' => 'integer'
]);
//Get All Student And View it inside the Tables
$students = Student::latest()->paginate($count);
return view('admin.components.students',compact('students'));
}
The Routes
Route::prefix('adminControl')->middleware('auth:admin')->group(function () {
Route::get('/students/{count?}',[StudentController::class,'index'])->name('student');
@MahmoudAdelAli I think you need to take a step back and learn what a query string is, instead of just sticking load of parameters in the path. Search engines are going to see those as distinct URLs and start penalising you for duplicate content.
Use query strings how they were intended:
/students?per_page=50
class StudentController extends Controller
{
public function index(Request $request)
{
$students = Student::paginate($request->query('per_page'));
return view('students.index', compact('students'));
}
}
If you want to ensure the per_page parameter is an integer and within a given range, you can do that:
$perPage = (int) $request->query('per_page', 15);
if ($perPage < 1 || $perPage > 100) {
abort(400, 'The per_page parameter must be an integer between 1 and 100');
}
$students = Student::paginate($perPage);
This will return a 400 Bad Request error if a user specifies a bad per_page parameter.
Please or to participate in this conversation.