If I have for example:
$project = new Project(); // Project is a class that extends Eloquent
$project->title;
$project->something;
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;
}
http://laravel.com/docs/4.2/eloquent#converting-to-arrays-or-json