I am using Laravel and I want Automatically deleting rows using Eloquent ORM .In laravel we have deleting
event .By using this "deleting" event we can do all the clean up or what we want to delete we are able to delete.
By using example that will explain in better way:
class User extends Eloquent
{
public function photos()
{
return $this->has_many('Photo');
}
// this is a recommended way to declare event handlers
protected static function boot() {
parent::boot();
static::deleting(function($user) { // before delete() method call this
$user->photos()->delete();
// do the rest of the cleanup...
});
}
}
Note:You should probably also put the whole thing inside a transaction, to ensure the referential integrity..
By this way we can achieve Automatically deleting rows using Eloquent ORM.
0 Comment(s)