/laravel-custom-soft-delete

Laravel package that use is_deleted flag for soft delete & retain deleted_at to keep track date of deletion

Primary LanguagePHP

Laravel Custom Soft Delete ( Laravel 5 Package )

php 5.5+ author

Installation

  1. add

     "repositories": [
         {
             "type": "vcs",
             "url":  "git@github.com:wilzokch/laravel-custom-soft-delete.git"
         }
     ],
    

    to your composer.json.

  2. run the composer require command from your terminal:

     composer require wilzokch/laravel-custom-soft-delete:dev-master
    
  3. add the Wilzokch\LaravelCustomSoftDelete\SoftDeletes trait to the model:

    <?php
    
    namespace App\Models;
    
    use Illuminate\Database\Eloquent\Model;
    use Wilzokch\LaravelCustomSoftDelete\SoftDeletes;
    
    class Flight extends Model
    {
        use SoftDeletes;
    }
    
  4. add soft delete columns to your migration

     use Illuminate\Database\Schema\Blueprint;
     use Illuminate\Support\Facades\Schema;
    
     Schema::table('flights', function (Blueprint $table) {
         $table->tinyInteger('is_deleted')->default(false)->index();
         $table->timestamp('deleted_at')->nullable();
     });
    
     Schema::table('flights', function (Blueprint $table) {
         $table->dropColumn('is_deleted');
         $table->dropColumn('deleted_at');
     });