Download the PHP package robotsinside/laravel-deletable without Composer

On this page you can find all versions of the php package robotsinside/laravel-deletable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-deletable

Laravel Deletable

Latest Version on Packagist Total Downloads CI License: MIT

This package can be used to gracefully handle the deletion of Eloquent models which are related to other models through HasOne, HasMany, BelongsTo, BelongsToMany or Morph* relationships.

It provides a number of helpful additions:

  1. Validate delete requests with the provided DeletableRequest class
  2. Check for the existence of related models before soft deleting a model instance
  3. Emulate the cascade behaviour provided at the DB layer

Table of contents

Installation

  1. Run composer require robotsinside/laravel-deletable.

  2. Optionally register the service provider in config/app.php

Auto-discovery is enabled, so this step can be skipped.

Usage

Use the RobotsInside\Deletable\Deletable trait in your models. You must also define a protected deletableConfig() method which returns the configuration array.

Use cases

1. Avoid SQLSTATE[23000]: Integrity constraint violation

A Post implements a HasMany relation with a Like model.

To avoid this error and provide the user with some more helpful feedback, we can use the DeletableRequest class.

Now we can display the Integrity contraint violation as validation errors instead..

2. Check if a model is deletable

This feature supports all relation types. It's particularly helpful when Laravel's soft deletes are in use, since soft-deleting always succeeds without throwing an Integrity Constraint Violation error.

3. Validate deletes

To validate delete requests, you can type-hint the provided RobotsInside\Deletable\Requests\DeletableRequest class in your controller method.

This class will attempt to automatically resolve the model's route binding, however it currently only supports a single URI route binding.

If your route has more than one binding, such as authors/{author}/posts/{post}, you'll need to create your own form request, which extends DeletableRequest and define a getRouteModel method which returns the models' route binding.

Below is an example for routes with more than one route binding. This is all that is required for validation to kick in.

As before, type-hint the extended form request in your controller.

4. Customising the validation messages

If you don't want to rely on the default validation messages, you can define a deletableValidationMessage method on your model. You are free to add custom messages for each related model that is preventing a delete.

Supported safeDelete modes (use when soft deleting)

When using the safeDelete method, you have the option of defining a mode to be used when deleting a record. The mode can be set on the model's deletableConfig array.

Note that the mode configuration key can be left empty in exception mode, but must be set for cascade and custom modes.

Exception mode (default)

Soft deleting a model in this situation will fail. If the model in question is referenced by another model, an UnsafeDeleteException will be thrown.

Cascade mode

In this mode related models will also be deleted.

Custom mode

  1. Set mode to custom.
  2. Set the handler method
  3. Define the handler method on the model

If soft deleting fails, the handler method is called.

Testing

Run the provided tests:

Security

If you discover any vulnerabilities, please email [email protected] instead of using the issue tracker.

Coffee Time

Will work for :coffee::coffee::coffee:

Buy Me A Coffee

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-deletable with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.5|^8.0
illuminate/database Version ^6.0|^8.0|^9.0
illuminate/support Version ^6.0|^8.0|^9.0
illuminate/http Version ^6.0|^8.0|^9.0
laravel/legacy-factories Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package robotsinside/laravel-deletable contains the following files

Loading the files please wait ....