Skip to content

Commit bb79f77

Browse files
committed
added soft deletes to thread model, fixes #6
1 parent 2ae5f9e commit bb79f77

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/Cmgmyr/Messenger/Models/Thread.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
use Carbon\Carbon;
44
use Illuminate\Database\Eloquent\Model as Eloquent;
55
use Illuminate\Database\Eloquent\ModelNotFoundException;
6+
use Illuminate\Database\Eloquent\SoftDeletingTrait;
67

78
class Thread extends Eloquent
89
{
10+
use SoftDeletingTrait;
11+
912
/**
1013
* The database table used by the model.
1114
*
@@ -20,6 +23,13 @@ class Thread extends Eloquent
2023
*/
2124
protected $fillable = ['subject'];
2225

26+
/**
27+
* The attributes that should be mutated to dates.
28+
*
29+
* @var array
30+
*/
31+
protected $dates = ['created_at', 'updated_at', 'deleted_at'];
32+
2333
/**
2434
* Messages relationship
2535
*
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
6+
class AddSoftdeletesToThreadsTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('threads', function (Blueprint $table) {
16+
$table->softDeletes();
17+
});
18+
}
19+
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('threads', function (Blueprint $table) {
29+
$table->dropColumn('deleted_at');
30+
});
31+
}
32+
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function ($table) {
8686
$table->increments('id');
8787
$table->string('subject');
8888
$table->timestamps();
89+
$table->softDeletes();
8990
}
9091
);
9192
}

0 commit comments

Comments
 (0)