Git Product home page Git Product logo

laravel-deletable's People

Contributors

f9web avatar laravel-shift avatar sald19 avatar ultrono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-deletable's Issues

Implement method to disable deletion check

Implement method to disable deletion checks, i.e. so the result of isDeletable() is always true and any checks within isDeletable() are skipped. The API would look something along the lines of: the following.

A user may have a "deletable" restriction:

namespace App;

use F9Web\LaravelDeletable\Traits\RestrictsDeletion;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
  use RestrictsDeletion;
  
  public function isDeletable() : bool
  {
    return $this->orders()->doesntExist();
  }  
}

Assuming the user had orders, the following would fail and the model would not be deleted:

$user->delete();

The following would allow the deletable check to be skipped and the model would be deleted:

$user->withoutDeletableRestrictions()->delete()

Add `NoneDeletableModel` trait to package

Ads a simple trait called NoneDeletableModel to the package. The trait could then be used in Eloquent models to deny all deletion attempts:

declare(strict_types=1);

namespace F9Web\LaravelDeletable\Traits\Traits;

use F9Web\LaravelDeletable\Traits\RestrictsDeletion;

trait NoneDeletableModel
{
    use RestrictsDeletion;

    public function isDeletable() : bool
    {
        return false;
    }
}

To prevent all deletion requests for a model:

declare(strict_types=1);

namespace App\Models;

use F9Web\LaravelDeletable\Traits\NoneDeletableModel;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
   use NoneDeletableModel;
}

Now, orders cannot be deleted.

Support mass delete

It would be nice to have support of mass delete, e.g. User::where('is_archived', true)->delete() . Something like isMassDeletable(): bool. Laravel SoftDeletes Trait supports mass delete, so its code may be helpful.

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.