PHP code example of exls / laravel-cascade-soft-deletes
1. Go to this page and download the library: Download exls/laravel-cascade-soft-deletes 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/ */
exls / laravel-cascade-soft-deletes example snippets
'providers' => array(
//register listeners on events
Exls\LaravelCascadeSoftDeletes\Providers\CascadeSoftDeletesServiceProvider::class,
),
namespace App\Models;
use App\Models\Master\Detail;
use Exls\LaravelCascadeSoftDeletes\Traits\CascadeSoftDeletes;
use Illuminate\Database\Eloquent\Model;
class Master extends Model
{
//Instead of SoftDeletes
use CascadeSoftDeletes;
//Remove immideately details
protected $cascadeDeletes = ['details'];
// or use queues to soft delete details
protected $queuedCascadeDeletes = ['details'];
protected $dates = ['deleted_at'];
public function details()
{
return $this->hasMany(Detail::class);
}
}
App\Models\Master::findOrFail($masterId)->delete()