Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Illuminate\Http\Request to array

I'm making in use of a library that expects to receive a native PHP array such as is obtained from the global $_REQUEST.

Unfortunately in this instance, the Illuminate\Http\Request is an object, and seems to have quite a different structure to the native php array. Is there a method to convert that object to the same array that would be obtained via '$_REQUEST' (which doesn't work inside a laravel controller method).

Thanks in advance.

like image 776
Gilles Major Avatar asked Sep 15 '15 12:09

Gilles Major


People also ask

What is illuminate HTTP request in laravel?

Laravel's Illuminate\Http\Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, cookies, and files that were submitted with the request.

What is HTTP request in laravel?

Laravel provides an expressive, minimal API around the Guzzle HTTP client, allowing you to quickly make outgoing HTTP requests to communicate with other web applications.

Which method allows you to verify that the incoming request path matches a given pattern?

rs. Path annotation in JAX-RS is used to define a URI matching pattern for incoming HTTP requests. It can be placed upon a class or on one or more Java methods.


1 Answers

Illuminate\Http\Request has some nice methods to turn it into arrays.

// Where $request is an Illuminate\Http\Request instance
$request->all(); // Returns array with all elements.
$request->only(['key1', 'key2']); // Returns array with selected items
$request->except(['key1']); // Returns array with everything except key1.

You should always check the class for methods you can use. Just browse through the files and see what they have to offer. It's fun and gives you a better understanding of the api.

Laravel really shines with its extensive documentation, make sure you take advantage of it.

like image 153
Chris Magnussen Avatar answered Oct 02 '22 17:10

Chris Magnussen