Add soft-deletes

This commit is contained in:
Daniel Supernault 2018-06-13 18:52:42 -06:00
parent 5cb3e5c17b
commit 4e51fbd5eb
10 changed files with 159 additions and 21 deletions

View file

@ -3,8 +3,16 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Avatar extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}

View file

@ -2,7 +2,7 @@
namespace App\Jobs\StatusPipeline;
use App\{Media, StatusHashtag, Status};
use App\{Media, Notification, StatusHashtag, Status};
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
@ -60,6 +60,9 @@ class StatusDelete implements ShouldQueue
}
$status->likes()->delete();
Notification::whereItemType('App\Status')
->whereItemId($status->id)
->delete();
StatusHashtag::whereStatusId($status->id)->delete();
$status->delete();

View file

@ -3,9 +3,19 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Like extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
public function actor()
{
return $this->belongsTo(Profile::class, 'profile_id', 'id');

View file

@ -2,11 +2,21 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Storage;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Media extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
public function url()
{
$path = $this->media_path;

View file

@ -3,9 +3,18 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Mention extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
public function profile()
{

View file

@ -3,9 +3,18 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Notification extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
public function actor()
{

View file

@ -5,9 +5,18 @@ namespace App;
use Storage;
use App\Util\Lexer\PrettyNumber;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Profile extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
protected $hidden = [
'private_key',
];

View file

@ -2,12 +2,21 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Storage;
use Vinkla\Hashids\Facades\Hashids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Status extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
public function profile()
{
return $this->belongsTo(Profile::class);
@ -43,6 +52,11 @@ class Status extends Model
return url($path);
}
public function editUrl()
{
return $this->url() . '/edit';
}
public function mediaUrl()
{
$media = $this->firstMedia();

View file

@ -3,11 +3,19 @@
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
use Notifiable, SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
* The attributes that are mass assignable.

View file

@ -0,0 +1,58 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddSoftDeletesToModels extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('avatars', function ($table) {
$table->softDeletes();
});
Schema::table('likes', function ($table) {
$table->softDeletes();
});
Schema::table('media', function ($table) {
$table->softDeletes();
});
Schema::table('mentions', function ($table) {
$table->softDeletes();
});
Schema::table('notifications', function ($table) {
$table->softDeletes();
});
Schema::table('profiles', function ($table) {
$table->softDeletes();
});
Schema::table('statuses', function ($table) {
$table->softDeletes();
});
Schema::table('users', function ($table) {
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}