Skip to content

Users

Domain model

Users

Using the User model

Warning

Never use JohnIt\Bc\Core\Domain\Models\User directly. Always use JohnIt\Bc\Core\Domain\Contacts\Models\UserContract. Otherwise it won’t be possible to change the user model via config.

For initialising a new instance of the user model always use the service container:

$user = app(UserContract::class);

When calling static methods on the user model your must do it like this:

$userClass = app(UserContract::class);
$user = $userClass::create([
    'name' => 'Max Meyer',
]);

When typehinting to the user model you must always typehint to the abstract UserContract class. Example:

use JohnIt\Bc\Core\Domain\Contracts\Models\UserContract;

class LicensePolicy
{
    public function create(UserContract $user): bool
    {
        return $user->can('mytenant.licenses.write');
    }
}

Using your own User model

You can use your own user model by publishing the bc-core.php configuration file to your main project and changing the bc-core.models.user settings key.