Be careful when constructing your custom filtered queries using GET parameters

1if (request()->has('since')) {
2 // example.org/?since=
3 // fails with illegal operator and value combination
4 $query->whereDate('created_at', '<=', request('since'));
5}
6 
7if (request()->input('name')) {
8 // example.org/?name=0
9 // fails to apply query filter because evaluates to false
10 $query->where('name', request('name'));
11}
12 
13if (request()->filled('key')) {
14 // correct way to check if get parameter has value
15}

Tip given by @mc0de

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