Laravel

How to get Laravel Elquent Data as an Array1 min read

To get data as an array from an Eloquent model, you can use the toArray() method.

Here’s an example:




This will retrieve all the users from the database and convert them into an array.

Alternatively, you can also use the toJson() method to get the data as a JSON string.

You can then decode the JSON string into an array using json_decode(), like this:

Leave a Comment