Propel uses Peer
classes, and doctrine used Table
classes as a way to manipulate respective objects and object properties, without having to pollute the actual object with static
methods.
After cursory glance of the laravel (eloquent) docs, I didn't see anything that eloquent provides for the same Peer
or Table
like functionality. My question is, does laravel (or eloquent) provide a namespace for such classes, or do I just use Table
and let autoloader take care of the rest?
// Example use of a table class in doctrine 1.2
$user = UserTable::getInstance()->findById(1);
-- Update 1 --
Layman example of how a doctrine table class may be used:
class UserTable
{
public static function getInstance()
{
return Doctrine_Core::getTable('User');
}
public function linkFoo($userId, array $foos)
{
$user = $this->findById($userId);
foreach ($foos as $foo) {
$user->foo = $foo;
$user->save();
}
}
}
// SomeController.php
executeSaveFoo()
{
UserTable::getInstance()->linkFoo($this->getUser(), array('foo1', 'foo2'));
}
The purpose of the doctrine table class is to provide an api for actions against respective objects which should not be in the controller, in the above example the linkFoo
class will link provided foos to the respective user object.
I feel the separation between objects and 'table' classes is important, as an object shouldn't know how to instantiate nor hydrate itself.