How to get a request with spaces in laravel?

by raphael_tillman , in category: PHP Frameworks , 10 months ago

How to get a request with spaces in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 10 months 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.

Related Threads:

How to logout with a get request in laravel?
How to get json from request in laravel?
How to get json post request in laravel?
How to handle multiple get request in laravel?
How to get data from ajax request in laravel?
How to get http request detail in laravel?