Skip to content

InteractsWithAccessCodes

Trafford Fewster edited this page Nov 13, 2023 · 1 revision

Summary

This page will cover the methods available to your models after using the trait on your model. The source for all these traits can be found here.

public function accessCodes(): MorphMany

Get the access codes. This method will return a MorphMany response for all the access codes related to the model.

public function getAccessCode(string $code): AccessCode

Gets the first access code assigned to the model.

public function generateAccessCode(BaseGenerator $generator = null): string

Generates an access code and assigns it to your model, it will then return the code. You can adjust the generator setting by passing a generator object as the first parameter. More on generators can be found here.

public function setAccessCode(string $code, BaseGenerator $generator = null): string

Set a specific access code to the model, you can also provide a generator as the 2nd augment to have custom validation rules.

public function checkAccessCode(string $code): bool

This will check if a specific access code string is assigned to the model.

public function deleteAccessCode(string $code): bool

Deletes a specific access code from the model, freeing it up to be used on a new model.

public static function findWithCode(string $code): ?self

Can be used to find a model based on the access code, this will then return the model if it finds one.