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 this2$perPage = request()->per_page ? request()->per_page : 20;3 4// You can do this5$perPage = request('per_page', 20);
Tip given by @devThaer