GithubHelp home page GithubHelp logo

softdeletesex's Introduction

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/

softdeletesex's People

Contributors

broly8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

digger5212

softdeletesex's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.