Skip to content

Commit

Permalink
add soft deletes to messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgmyr committed Apr 8, 2017
1 parent 17a548e commit 1cdf7c3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Cmgmyr/Messenger/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Cmgmyr/Messenger/Models/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function users()
*/
public function creator()
{
return $this->messages()->oldest()->first()->user;
return $this->messages()->withTrashed()->oldest()->first()->user;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddSoftDeletesToMessagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('messages', function (Blueprint $table) {
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('messages', function (Blueprint $table) {
$table->dropSoftDeletes();
});
}
}

0 comments on commit 1cdf7c3

Please sign in to comment.