PHP code example of gigerit / laravel-cascade-delete
1. Go to this page and download the library: Download gigerit/laravel-cascade-delete 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/ */
gigerit / laravel-cascade-delete example snippets
namespace App\Models;
use Gigerit\LaravelCascadeDelete\Concerns\CascadeDeletes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model
{
use SoftDeletes;
use CascadeDeletes;
protected $cascadeDeletes = [
'posts', // HasMany
'profile', // HasOne
'roles', // BelongsToMany (will detach)
'comments', // MorphMany
];
public function posts()
{
return $this->hasMany(Post::class);
}
public function profile()
{
return $this->hasOne(Profile::class);
}
public function roles()
{
return $this->belongsToMany(Role::class);
}
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
}