Request parameter default value

Here we are checking if there is a per_page (or any other parameter) value then we will use it, otherwise, we will use a default one.

1// Isteand of this
2$perPage = request()->per_page ? request()->per_page : 20;
3 
4// You can do this
5$perPage = request('per_page', 20);

Tip given by @devThaer

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord