<?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());
});
}
];
}
}