Skip to content

Conversation

@imliam
Copy link
Contributor

@imliam imliam commented Oct 4, 2025

-$name = $request->input('name');
-$age = (int) $request->get('age');
-$price = (float) $request->data('price');
-$isActive = (bool) $request['is_active'];
+$name = $request->string('name');
+$age = $request->integer('age');
+$price = $request->float('price');
+$isActive = $request->boolean('is_active');

@alexey-m-ukolov
Copy link

I like the idea just want to point out that $request->input('name') and $request->string('name') are not the same - former returns (in this example) string|null and latter returns \Illuminate\Support\Str.
I'm not sure if this case should be handled at all - even if we replace with $request->string('name')->toString() we are still losing null. I think only the explicit casts and calls like $request->input('name', '') can be safely replaced (with added ->toString()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants