How to get a request with spaces in laravel?

by raphael_tillman , in category: PHP Frameworks , 14 days ago

How to get a request with spaces in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 13 days ago

@raphael_tillman 

To get a request with spaces in Laravel, you can use the url() helper function to generate the URL with spaces encoded as %20. Here's an example:

1
2
3
4
5
6
7
use IlluminateHttpRequest;

Route::get('/example', function (Request $request) {
    $urlWithSpaces = url('/example with spaces');
    
    return response()->json(['url' => $urlWithSpaces]);
});


In this example, the generated URL will be /example%20with%20spaces. When you access this URL in your browser, Laravel will automatically decode the %20 to spaces in the request object.