Skip to content

Laravel 5.* SoftDeletes Extend, change the deleted_at field to int

License

Notifications You must be signed in to change notification settings

broly8/SoftDeletesEx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SoftDeletesEx

Laravel 5.* SoftDeletes Extend

Create a SoftDeletes table

As follow,

CREATE TABLE `sample` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `column1` varchar(45) NOT NULL DEFAULT '',
  `column2` varchar(45) NOT NULL DEFAULT '',
  `column3` varchar(45) NOT NULL DEFAULT '',
  `deleted_at` bigint(20) unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `column1_UNIQUE` (`column1`,`deleted_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='sample';
  • Make the columns column1, deleted_at unique together
  • The column deleted_at should be NOT NULL, bigint, DEFAULT '0'

Create a model

sample.php

<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\SoftDeletesEx as SoftDeletes;

class Sample extends Model {
	use SoftDeletes;

    /**
     * Indicates if the model should be timestamped.
     *
     * @var  bool
     */
    public $timestamps = false;

    /**
     * The table associated with the model.
     *
     * @var  string
     */
    protected $table = 'sample';
}

Use trait SoftDeletesEx:

use App\Models\SoftDeletesEx as SoftDeletes;

Link

My blog post: https://blog.dreamlikes.cn/2017/06/07/laravel5-extend-softdeletes/

About

Laravel 5.* SoftDeletes Extend, change the deleted_at field to int

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages