# BaseModel

> Base implementation of UIAwesome\Model\ModelInterface.

[API reference](/docs/api/index.md) › [Model](/docs/extensions/model/reference/index.md) › BaseModel

| abstract class | `UIAwesome\Model\BaseModel` |
| --- | --- |
| Implements | [`ModelInterface`](/docs/extensions/model/reference/modelinterface/index.md) |
| Source | [`src/BaseModel.php`](https://github.com/ui-awesome/model/blob/main/src/BaseModel.php#L20) |

1 subclass:

- [`UIAwesome\FormModel\BaseFormModel`](/docs/extensions/form-model/reference/baseformmodel/index.md)

Base implementation of [`ModelInterface`](/docs/extensions/model/reference/modelinterface/index.md).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`add()`](#method-add) | Registers a property and its supported types. | `BaseModel` |
| [`getData()`](#method-getData) | Returns the raw input retained after loading. | `BaseModel` |
| [`getModelName()`](#method-getModelName) | Returns the model class name used as the default input scope. | `BaseModel` |
| [`getNames()`](#method-getNames) | Returns property names, expanding nested models with dot notation. | `BaseModel` |
| [`getTypes()`](#method-getTypes) | Returns collected property types indexed by property name. | `BaseModel` |
| [`getValue()`](#method-getValue) | Returns a property value, including nested model paths. | `BaseModel` |
| [`has()`](#method-has) | Checks whether a property or nested model path exists. | `BaseModel` |
| [`isEmpty()`](#method-isEmpty) | Checks whether the loaded raw input is empty. | `BaseModel` |
| [`isType()`](#method-isType) | Checks whether a property supports the requested type. | `BaseModel` |
| [`load()`](#method-load) | Assigns scoped or unscoped input and retains its raw keys. | `BaseModel` |
| [`setValue()`](#method-setValue) | Assigns a property value using its attributes and type metadata. | `BaseModel` |
| [`setValues()`](#method-setValues) | Assigns input values while excluding the selected property names. | `BaseModel` |
| [`toArray()`](#method-toArray) | Exports property values with optional top-level snake_case keys. | `BaseModel` |

## Method details

### add() <span id="method-add"></span>

```php
public function add(string $property, string|array $type): void
```

Registers a property and its supported types.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$property` | `string` |  |
| `$type` | `string\|array` |  |

### getData() <span id="method-getData"></span>

```php
public function getData(): array
```

Returns the raw input retained after loading.

**Returns**

`array`

### getModelName() <span id="method-getModelName"></span>

```php
public function getModelName(): string
```

Returns the model class name used as the default input scope.

**Returns**

`string`

### getNames() <span id="method-getNames"></span>

```php
public function getNames(): array
```

Returns property names, expanding nested models with dot notation.

**Returns**

`array`

### getTypes() <span id="method-getTypes"></span>

```php
public function getTypes(): array
```

Returns collected property types indexed by property name.

**Returns**

`array`

### getValue() <span id="method-getValue"></span>

```php
public function getValue(string $property): mixed
```

Returns a property value, including nested model paths.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$property` | `string` |  |

**Returns**

`mixed`

### has() <span id="method-has"></span>

```php
public function has(string $property): bool
```

Checks whether a property or nested model path exists.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$property` | `string` |  |

**Returns**

`bool`

### isEmpty() <span id="method-isEmpty"></span>

```php
public function isEmpty(): bool
```

Checks whether the loaded raw input is empty.

**Returns**

`bool`

### isType() <span id="method-isType"></span>

```php
public function isType(string $property, string $type): bool
```

Checks whether a property supports the requested type.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$property` | `string` |  |
| `$type` | `string` |  |

**Returns**

`bool`

### load() <span id="method-load"></span>

```php
public function load(iterable $data, string|null $modelName = null): bool
```

Assigns scoped or unscoped input and retains its raw keys.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `iterable` |  |
| `$modelName` | `string\|null` |  |

**Returns**

`bool`

### setValue() <span id="method-setValue"></span>

```php
public function setValue(string $property, mixed $value): void
```

Assigns a property value using its attributes and type metadata.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$property` | `string` |  |
| `$value` | `mixed` |  |

### setValues() <span id="method-setValues"></span>

```php
public function setValues(array $data, array $except = []): void
```

Assigns input values while excluding the selected property names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `array` |  |
| `$except` | `array` |  |

### toArray() <span id="method-toArray"></span>

```php
public function toArray(bool $snakeCase = false, array $exceptProperties = []): array
```

Exports property values with optional top-level snake_case keys.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$snakeCase` | `bool` |  |
| `$exceptProperties` | `array` |  |

**Returns**

`array`