PHP code example of shiftonelabs / laravel-cascade-deletes
1. Go to this page and download the library: Download shiftonelabs/laravel-cascade-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/ */
shiftonelabs / laravel-cascade-deletes example snippets
php
namespace App;
use Illuminate\Database\Eloquent\Model;
use ShiftOneLabs\LaravelCascadeDeletes\CascadesDeletes;
class User extends Model {
use CascadesDeletes;
protected $cascadeDeletes = ['posts', 'profile'];
public function posts()
{
return $this->hasMany(Post::class);
}
public function profile()
{
return $this->hasOne(Profile::class);
}
public function type()
{
return $this->belongsTo(Type::class);
}
}
php
namespace App;
use Illuminate\Database\Eloquent\Model;
use ShiftOneLabs\LaravelCascadeDeletes\CascadesDeletes;
class Profile extends Model {
use CascadesDeletes;
protected $cascadeDeletes = ['addresses'];
public function user()
{
return $this->belongsTo(User::class);
}
public function addresses()
{
return $this->morphMany(Address::class, 'addressable');
}
}