class BaseModel implements ModelInterface

A base database object (e.g. A player or a team)

Constants

TABLE

The name of the database table used for queries You can use this constant in static methods as such: static::TABLE

Methods

static BaseModel
get(int|BaseModel $id)

Get a Model based on its ID

void
update(string $name, mixed $value)

Update a database field

void
delete()

Delete the object

void
wipe()

Permanently delete the object from the database

int
getId()

Get an object's database ID

bool
isValid()

See if an object is valid

static string
getEagerColumns()

Get the MySQL columns that will be loaded as soon as the model is created

static Model
fetchFromSlug(string|int $slug)

Gets an entity from the supplied slug, which can either be an alias or an ID

refresh()

Fetch a model's data from the database again

static Model
invalid()

Generate an invalid object

Details

at line line 61
static BaseModel get(int|BaseModel $id)

Get a Model based on its ID

Parameters

int|BaseModel $id The ID of the object to look for, or the object itself

Return Value

BaseModel

Exceptions

InvalidArgumentException If $id is an object of an incorrect type

at line line 132
void update(string $name, mixed $value)

Update a database field

Parameters

string $name The name of the column
mixed $value The value to set the column to

Return Value

void

at line line 144
void delete()

Delete the object

Please note that this does not delete the object entirely from the database, it only hides it from users. You should overload this function if your object does not have a 'status' column which can be set to 'deleted'.

Return Value

void

at line line 153
void wipe()

Permanently delete the object from the database

Return Value

void

at line line 162
int getId()

Get an object's database ID

Return Value

int The ID

at line line 171
bool isValid()

See if an object is valid

Return Value

bool

at line line 318
static string getEagerColumns()

Get the MySQL columns that will be loaded as soon as the model is created

Return Value

string The columns in a format readable by MySQL

at line line 384
static Model fetchFromSlug(string|int $slug)

Gets an entity from the supplied slug, which can either be an alias or an ID

Parameters

string|int $slug The object's slug

Return Value

Model

at line line 436
BaseModel refresh()

Fetch a model's data from the database again

Return Value

BaseModel The new model

at line line 460
static Model invalid()

Generate an invalid object

<?php $object = Team::invalid();

get_class($object); // Team
$object->isValid(); // false

Return Value

Model