Can you iterate over the properties of an eloquent object?

If I have for example:

$project = new Project(); // Project is a class that extends Eloquent

Is it possible to iterate over those properties... something like this:

foreach( $project as $key => $value )
    echo $key;

I am trying to do this to achieve a unit of work for editing Eloquent models


You can use the toArray() method:

foreach( $project->toArray() as $key => $value )
    echo $key;

You can also use getAttributes() method:

foreach ($project->getAttributes() as $k => $v) {
    echo $k.' '.$v."<br />";

Need Your Help

Java only allow two drawn circles to be selected at a time, how to unselect

java swing user-interface select unselect

Hey so I've got 20 circles displayed on a screen, I want the user to be able to select only two circles and be able to unselect circles but still only have maximum 2 circles selected. I know how to...

Set description on DataContract members

wcf c#-4.0 serialization

I would like to control whats on the help pages, and especially information about each field that. For example, I have this class: