{"repo":"f9webltd/laravel-deletable","free":true,"listed":false,"github":"https://github.com/f9webltd/laravel-deletable","clone":"git clone https://github.com/f9webltd/laravel-deletable.git","description":":space_invader: Gracefully restrict deletion of Laravel Eloquent models","language":"PHP","stars":158,"topics":["eloquent","laravel-softdeletes-trait","laravel-softdelete","eloquent-models","eloquent-orm","laravel-delete","laravel-package","laravel"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"Laravel Deletable Gracefully handle deletion restrictions on your Eloquent models, as featured on Laravel News Requirements PHP ^8.2 Laravel ^11.0 / ^12.0 / ^13.0 The package supports actively supported Laravel releases as per the official Laravel Support Policy. For legacy support (older Laravel and PHP versions) use 1.0.6 or 2.1.0. Installation The package will automatically register itself. Optionally publish the configuration file by running: php artisan vendor:publish and selecting the appropriate package. Documentation ### Usage Within an Eloquent model use the RestrictsDeletion trait: The trait overrides calls to Eloquent's delete() method. Implement the isDeletable() method within the model in question. This method should return true to allow deletion and false to deny deletion: The above denies deletion of users with orders. None deletable models throw an exception when the isDeletable() method returns false : Eloquent Base Model As the default isDeletable() method returns true , a base Eloquent model can be optionally defined from which all models extend. Each model can then optionally implement the isDeletable() method as needed. Customising Messages The default exception message is defined within the config f9web-laravel-deletable.messages.default and is simply The model cannot be deleted . By setting f9web-laravel-deletable.messages.default to null a more detailed message is automatically generated i.e. Restricted deletion: App\\User - 1 is not deletable . Custom ","default_branch":null,"files":null,"tree":[],"storefront":"/r/f9webltd","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/f9webltd/laravel-deletable/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}