PHP code example of joggapp / laravel-cascade-soft-deletes

1. Go to this page and download the library: Download joggapp/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/ */

    

joggapp / laravel-cascade-soft-deletes example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use JoggApp\LaravelCascadeSoftDeletes\Traits\CascadeSoftDeletes;

class User extends Model
{
    use SoftDeletes, CascadeSoftDeletes;

    protected $cascadeSoftDeletes = [
        'posts',
    ];

    public function posts()
    {
        return $this->hasMany(Post::class);
    }
}

$user = App\Models\User::find($userId);
$user->delete(); // Soft delete the user, which will also trigger the delete() method on any posts and their children.