Čamo's avatar
Level 3

Laravel 9 request->get() adds two spaces after the value

I am little confused, cause I supposed that request->get() will trim the value which came as query parameter. What is worse is that I am pretty sure that the value does not contain any spaces at the end. The request comes from Postman like query param in form

/dashboard?period=past_7_days

Then I call $request get('period'); and the result is past_7_days with two spaces at the and of the string. Can somebody tell me please what could happened there?

The controller code looks like

 public function index(Request $request, DatePeriodMaker $datePeriodMaker): JsonResponse
 {
     $periodType = trim($request->get('period'));  // Its weird but it seems to be necessary
     ....
 }

As I see the trin does not work on this. Its really weird.

0 likes
4 replies
JussiMannisto's avatar

You should use $request->input() instead of $request->get().

But show your full controller code. The answer may lie there.

Čamo's avatar
Level 3

I am sorry the two spaces adds Log::info()

Please or to participate in this conversation.