Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jeanpaul's avatar

Checking if a request parameter exists and is not empty

I have been logging request parameter checks, ht all are false.

this is my check:

if( $request->exists('id') ){ Log::info( 'request->exists(id) true' ); } else { Log::info( 'request->exists(id) false' ); }

if( $request->filled('id') ){ Log::info( 'request->filled(id) true' ); } else { Log::info( 'request->filled(id) false' ); }

if( $request->has('id') ){ Log::info( 'request->has(id) true' ); } else { Log::info( 'request->has(id) false' ); }

Log::info( 'Actual $request->id = ' . $request->id );

and this is the log file:

[2018-08-25 15:01:38] local.INFO: request->exists(id) false [2018-08-25 15:01:38] local.INFO: request->filled(id) false [2018-08-25 15:01:38] local.INFO: request->has(id) false [2018-08-25 15:01:38] local.INFO: Actual $request->id = 3

So, the $request->id has a value but all checkf return false.

What am i doing wrong?

0 likes
4 replies
crnkovic's avatar

OP, try dd($request->input('id'); $request->has('id')); and post it here.

1 like
jeanpaul's avatar

Hi crnKovic,

My mistake, i am passing a parameter as {id} in my route, not as a post parameter.

The thing i now don't understand is that $request->id still had the correct value if the route parameter existed.

Do you know if this is expected behaviour?

jlrdw's avatar

Is this coming from a form, if so can you show.

Usually parameters are just that, parameters.

jeanpaul's avatar

Hi Jlrdw,

I found my error. I am passing an id via my route. I have two routes:

Route::get('/backoffice/contracts/offers', 'ContractController@offers'); Route::get('/backoffice/contracts/offers/{id}', 'ContractController@offers');

if an id is passed to my controller i query for the id rows, if no id is passed to my controller i query all rows. So i wanted to know if the id existed and i was using $request->id but i have to check if request()->route('id') exists.

Now it works as intended.

Please or to participate in this conversation.