Home
NexoPOS

Method Filter: getDeclaredDependencies

This filter, which applies to models using the NsDependable trait, is used to mutate or extend the dependency resources checked while deleting any entity. You'll replace "Class" with the relevant Crud class for which you would like to extend the dependencies check.


<?php
namespace Modules\YourModule\Providers;

use Illuminate\Support\Provider as CoreProvider;
use App\Classes\Hook;
use App\Classes\Model;
use App\Models\User;
use Modules\YourModule\Models\Book;

class ServiceProvider extends CoreProvider
{
    public function register()
    {
        Hook::filter( User::method( 'setDependencies' ), function( $dependants ) {
            $dependants[ Book::class ]  =   Model::dependant(
                local_index: 'id',
                local_name: 'name',
                foreign_index: 'user_id',
                foreign_name: 'name'
            );
            
            return $dependants;
        });
    }
}

In the above example, we're extending the user-declared dependency to ensure a user is not deleted if they're still referenced on the book table.