PHP code example of totov / laravel-soft-delete-morph-to-many-pivots

1. Go to this page and download the library: Download totov/laravel-soft-delete-morph-to-many-pivots 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/ */

    

totov / laravel-soft-delete-morph-to-many-pivots example snippets


use Illuminate\Database\Eloquent\Model;
use Totov\LaravelSoftDeleteMorphToManyPivots\MorphToManySoftDeletes;
use Totov\LaravelSoftDeleteMorphToManyPivots\Traits\MorphToManySoftDeletesTrait;

class User extends Model
{
    use MorphToManySoftDeletesTrait;

    public function user_types(): MorphToManySoftDeletes
    {
        return $this->morphToManySoft(UserType::class, 'types');
    }
}

use Illuminate\Database\Eloquent\Model;
use Totov\LaravelSoftDeleteMorphToManyPivots\MorphToManySoftDeletes;
use Totov\LaravelSoftDeleteMorphToManyPivots\Traits\MorphToManySoftDeletesTrait;

class UserType extends Model
{
    use MorphToManySoftDeletesTrait;

    public function users(): MorphToManySoftDeletes
    {
        return $this->morphedByManySoft(User::class, 'types');
    }
}