class BaseModel extends Model (View source)

Base model used to provide UUID (binary) primary keys and automatic conversion.

This abstract model standardizes UUID handling for all Eloquent models that extend it.

  • Uses binary UUIDs as primary keys in the database.
  • Automatically converts UUIDs between binary (DB) and string (application).
  • Automatically generates a UUID when creating new records.

Properties

bool $incrementing

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

protected string $keyType

The data type of the primary key ID.

Methods

string|null
getIdAttribute(mixed $value)

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

static void
boot()

Boot function for the model.

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 function for the model.

This ensures that every new record automatically gets a UUID assigned if no ID is provided during creation.

Return Value

void