From 1cdf7c3301fb129dd6fbd94928807085a2caa950 Mon Sep 17 00:00:00 2001 From: Chris Gmyr Date: Thu, 30 Mar 2017 11:44:11 -0400 Subject: [PATCH] add soft deletes to messages --- src/Cmgmyr/Messenger/Models/Message.php | 3 ++ src/Cmgmyr/Messenger/Models/Thread.php | 2 +- ...742_add_soft_deletes_to_messages_table.php | 32 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/migrations/2017_03_30_152742_add_soft_deletes_to_messages_table.php diff --git a/src/Cmgmyr/Messenger/Models/Message.php b/src/Cmgmyr/Messenger/Models/Message.php index be893ed..9b5c5a6 100644 --- a/src/Cmgmyr/Messenger/Models/Message.php +++ b/src/Cmgmyr/Messenger/Models/Message.php @@ -3,9 +3,12 @@ namespace Cmgmyr\Messenger\Models; use Illuminate\Database\Eloquent\Model as Eloquent; +use Illuminate\Database\Eloquent\SoftDeletes; class Message extends Eloquent { + use SoftDeletes; + /** * The database table used by the model. * diff --git a/src/Cmgmyr/Messenger/Models/Thread.php b/src/Cmgmyr/Messenger/Models/Thread.php index cd65fe5..88ed58e 100644 --- a/src/Cmgmyr/Messenger/Models/Thread.php +++ b/src/Cmgmyr/Messenger/Models/Thread.php @@ -95,7 +95,7 @@ public function users() */ public function creator() { - return $this->messages()->oldest()->first()->user; + return $this->messages()->withTrashed()->oldest()->first()->user; } /** diff --git a/src/migrations/2017_03_30_152742_add_soft_deletes_to_messages_table.php b/src/migrations/2017_03_30_152742_add_soft_deletes_to_messages_table.php new file mode 100644 index 0000000..e7bf7ff --- /dev/null +++ b/src/migrations/2017_03_30_152742_add_soft_deletes_to_messages_table.php @@ -0,0 +1,32 @@ +softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('messages', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + } +}