class Loan extends BaseModel (View source)

Represents a loan (borrowed copy) in the system.

Each loan is associated with a student and a specific copy of a book. Automatically generates a unique barcode code and sets the start date on creation.

Properties

bool $incrementing

Indicates that the model does not use auto-incrementing IDs.

from  BaseModel
protected string $keyType

The data type of the primary key ID.

from  BaseModel
bool $timestamps

Indicates that the model does not use timestamps.

protected string $table

The database table used by this model.

protected array<int,string> $fillable

The attributes that are mass assignable.

Methods

string|null
getIdAttribute(mixed $value)

Converts the binary UUID stored in the database into a string UUID.

static void
boot()

Boot method to handle model events.

string|null
getStudentIdAttribute(mixed $value)

Converts the stored binary student ID to UUID string.

string|null
getCopyIdAttribute(mixed $value)

Converts the stored binary copy ID to UUID string.

static string
generateBarCode(string $prefix = 'LN', int $length = 8)

Generates a unique barcode code for the loan.

BelongsTo
student()

Defines the relationship to the student who borrowed the copy.

BelongsTo
copy()

Defines the relationship to the borrowed copy.

Details

string|null getIdAttribute(mixed $value)

Converts the binary UUID stored in the database into a string UUID.

Parameters

mixed $value

binary value from the database

Return Value

string|null

UUID in string format, or null if not set

static protected void boot()

Boot method to handle model events.

Automatically sets the barcode and start date when creating a new loan.

Return Value

void

string|null getStudentIdAttribute(mixed $value)

Converts the stored binary student ID to UUID string.

Parameters

mixed $value

Return Value

string|null

string|null getCopyIdAttribute(mixed $value)

Converts the stored binary copy ID to UUID string.

Parameters

mixed $value

Return Value

string|null

static string generateBarCode(string $prefix = 'LN', int $length = 8)

Generates a unique barcode code for the loan.

Parameters

string $prefix

prefix to prepend to the code

int $length

length of the random part of the code

Return Value

string

BelongsTo student()

Defines the relationship to the student who borrowed the copy.

Return Value

BelongsTo

BelongsTo copy()

Defines the relationship to the borrowed copy.

Return Value

BelongsTo