Skip to content

Commit

Permalink
askedio/laravel-soft-cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
liyu001989 committed Aug 24, 2018
1 parent 5092002 commit 778a67d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/Models/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Models;

use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\SoftDeletes;

class Reply extends Model
{
use Filterable;
use Filterable, SoftDeletes;

protected $fillable = ['content'];

Expand Down
6 changes: 5 additions & 1 deletion app/Models/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace App\Models;

use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Askedio\SoftCascade\Traits\SoftCascadeTrait;

class Topic extends Model
{
use Filterable;
use Filterable, SoftDeletes, SoftCascadeTrait;

protected $softCascade = ['replies'];

protected $fillable = ['title', 'body', 'category_id', 'excerpt', 'slug'];

Expand Down
5 changes: 0 additions & 5 deletions app/Observers/TopicObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,4 @@ public function saved(Topic $topic)
dispatch(new TranslateSlug($topic));
}
}

public function deleted(Topic $topic)
{
\DB::table('replies')->where('topic_id', $topic->id)->delete();
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "project",
"require": {
"php": ">=7.0.0",
"askedio/laravel-soft-cascade": "^5.5",
"awssat/laravel-visits": "^1.4",
"barryvdh/laravel-cors": "^0.11.0",
"barryvdh/laravel-snappy": "^0.4.1",
Expand Down
51 changes: 50 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

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

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

Schema::table('replies', function(Blueprint $table) {
$table->softDeletes();
});
}

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

Schema::table('replies', function(Blueprint $table) {
$table->dropSoftDeletes();
});
}
}

0 comments on commit 778a67d

Please sign in to comment.