PHP code example of razisayyed / laravel-cascaded-soft-deletes

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

    

razisayyed / laravel-cascaded-soft-deletes example snippets


...


use \Illuminate\Database\Eloquent\Model;
use \Illuminate\Database\Eloquent\SoftDeletes;
use RaziAlsayyed\LaravelCascadedSoftDeletes\Traits\CascadedSoftDeletes;

class Page extends Model {

    use SoftDeletes;
    use CascadedSoftDeletes;

    protected $cascadedSoftDeletes = [ 'blocks' ];

    public function blocks()
    {
        return $this->hasMany(Block::class);
    }

}



use \Illuminate\Database\Eloquent\Model;
use \Illuminate\Database\Eloquent\SoftDeletes;

class Block extends Model {

    use SoftDeletes;

    public function page() 
    {
        return $this->belongsTo(Page::class);
    }

}

...


use \Illuminate\Database\Eloquent\Model;
use \Illuminate\Database\Eloquent\SoftDeletes;
use RaziAlsayyed\LaravelCascadedSoftDeletes\Traits\CascadedSoftDeletes;

class Folder extends Model {

    use SoftDeletes;
    use NodeTrait;
    use CascadedSoftDeletes;

    public function albums()
    {
        return $this->hasMany(Album::class);
    }

    protected function getCascadedSoftDeletes()
    {
        return [
            'albums' => function() {
                return Album::whereHas('folder', function($q) {
                    $q->withTrashed()
                        ->where('_lft', '>=', $this->getLft())
                        ->where('_rgt', '<=', $this->getRgt());
                });  
            }
        ];
    }

}

php artisan vendor:publish --provider="RaziAlsayyed\LaravelCascadedSoftDeletes\Providers\CascadedSoftDeletesProvider" --tag="config"