1. Go to this page and download the library: Download f9webltd/laravel-deletable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
f9webltd / laravel-deletable example snippets
namespace App;
use F9Web\LaravelDeletable\Traits\RestrictsDeletion;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use RestrictsDeletion;
}
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();
}
}
namespace App\Controllers;
use F9Web\LaravelDeletable\Exceptions\NoneDeletableModel;
use App\User;
class UsersController
{
public function destroy(User $user) : bool
{
try {
$user->delete();
} catch (NoneDeletableModel $e) {
// dd($ex->getMessage());
}
}
}
namespace App;
use F9Web\LaravelDeletable\Traits\RestrictsDeletion;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class User extends Model
{
use RestrictsDeletion;
public function isDeletable() : bool
{
if (Str::endsWith($this->email, 'f9web.co.uk')) {
return $this->denyDeletionReason('Users with f9web.co.uk company email addresses cannot be deleted');
}
return true;
}
}
namespace App;
use F9Web\LaravelDeletable\Traits\RestrictsDeletion;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class User extends Model
{
use RestrictsDeletion;
public function isDeletable() : bool
{
if (Str::endsWith($this->email, 'f9web.co.uk')) {
return $this->denyDeletionReason('Users with f9web.co.uk company email addresses cannot be deleted');
}
if ($this->orders->isNotEmpty()) {
return false;
}
if ($this->purchaseOrders->isNotEmpty()) {
return $this->denyDeletionReason('This user has active purchase orders and cannot be deleted');
}
if ($this->overdueInvoices->isNotEmpty()) {
return $this->denyDeletionReason('Users with overdue invoices cannot be deleted');
}
return true;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.