Skip to content

Commit 5cfe81e

Browse files
committed
Adding custom SoftDeletingTrait for Laravel 4.2
1 parent e69a072 commit 5cfe81e

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,22 @@ You may also specify additional columns to update:
245245
User::where('age', '29')->increment('age', 1, array('group' => 'thirty something'));
246246
User::where('bmi', 30)->decrement('bmi', 1, array('category' => 'overweight'));
247247

248+
**Soft deleting**
249+
250+
When soft deleting a model, it is not actually removed from your database. Instead, a deleted_at timestamp is set on the record. To enable soft deletes for a model, apply the SoftDeletingTrait to the model:
251+
252+
use Jenssegers\Mongodb\Eloquent\SoftDeletingTrait;
253+
254+
class User extends Eloquent {
255+
256+
use SoftDeletingTrait;
257+
258+
protected $dates = ['deleted_at'];
259+
260+
}
261+
262+
For more information check http://laravel.com/docs/eloquent#soft-deleting
263+
248264
### MongoDB specific operators
249265

250266
**Exists**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php namespace Jenssegers\Mongodb\Eloquent;
2+
3+
trait SoftDeletingTrait {
4+
5+
use \Illuminate\Database\Eloquent\SoftDeletingTrait;
6+
7+
/**
8+
* Get the fully qualified "deleted at" column.
9+
*
10+
* @return string
11+
*/
12+
public function getQualifiedDeletedAtColumn()
13+
{
14+
return $this->getDeletedAtColumn();
15+
}
16+
17+
}

tests/models/Soft.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

33
use Jenssegers\Mongodb\Model as Eloquent;
4+
use Jenssegers\Mongodb\Eloquent\SoftDeletingTrait;
45

56
class Soft extends Eloquent {
67

8+
use SoftDeletingTrait;
9+
710
protected $collection = 'soft';
8-
protected $softDelete = true;
11+
protected $dates = array('deleted_at');
912

10-
}
13+
}

0 commit comments

Comments
 (0)