Unit
Represents a unit within a Laravel Neuro Corporation.
A unit can have multiple datasets and agents, and defines a default receiver for handling communication. You can think of it as a company department. The Unit class is responsible for storing configuration data and installing itself into the database by creating a corresponding NetworkUnit record, along with its associated data set templates and agents.
Table of Contents
Properties
- $agents : Collection
- A collection of Agent instances associated with the unit.
- $dataSets : Collection
- A collection of dataset configurations associated with the unit.
- $defaultReceiver : string
- The default receiver name for the unit.
- $defaultReceiverType : UnitReceiver
- The type of the default receiver, as defined by the UnitReceiver enum.
- $description : string
- A short description of the unit.
- $name : string
- The name of the unit.
Methods
- __construct() : mixed
- Unit constructor.
- configureDataSet() : self
- Configures a dataset for the unit.
- getDataSet() : mixed
- Retrieves a dataset by name.
- getDefaultReceiver() : array<string|int, mixed>
- Retrieves the default receiver configuration.
- getDescription() : string
- Retrieves the unit's description.
- getName() : string
- Retrieves the unit's name.
- install() : array<string|int, mixed>
- Installs the unit into the database.
- pushAgent() : self
- Adds an Agent instance to the unit.
- setDefaultReceiver() : void
- Sets the default receiver for the unit.
- setDescription() : self
- Sets the unit's description.
- setName() : self
- Sets the unit's name.
Properties
$agents
A collection of Agent instances associated with the unit.
public
Collection
$agents
$dataSets
A collection of dataset configurations associated with the unit.
public
Collection
$dataSets
$defaultReceiver
The default receiver name for the unit.
public
string
$defaultReceiver
$defaultReceiverType
The type of the default receiver, as defined by the UnitReceiver enum.
public
UnitReceiver
$defaultReceiverType
$description
A short description of the unit.
public
string
$description
$name
The name of the unit.
public
string
$name
Methods
__construct()
Unit constructor.
public
__construct([bool $load = false ]) : mixed
Optionally loads an existing unit (if $load is true) or initializes empty collections for datasets and agents.
Parameters
- $load : bool = false
-
If true, load an existing unit from the model by unit ID.
configureDataSet()
Configures a dataset for the unit.
public
configureDataSet(string $name, string $completion, object $data) : self
Validates that the provided data, once JSON-encoded, is valid JSON. Adds a dataset configuration, including a name, a completion prompt, and a JSON-encoded structure.
Parameters
- $name : string
-
The name of the dataset.
- $completion : string
-
The prompt to use for completion.
- $data : object
-
The dataset structure as an object.
Tags
Return values
self —Returns the current instance for chaining.
getDataSet()
Retrieves a dataset by name.
public
getDataSet(string $name) : mixed
Parameters
- $name : string
-
The name of the dataset to retrieve.
Return values
mixed —The dataset, or null if not found.
getDefaultReceiver()
Retrieves the default receiver configuration.
public
getDefaultReceiver(string $type, string $name) : array<string|int, mixed>
Returns an associative array containing the type and name of the default receiver.
Parameters
- $type : string
-
(Unused) Intended receiver type filter.
- $name : string
-
(Unused) Intended receiver name filter.
Return values
array<string|int, mixed> —An array with keys "type" and "name" for the default receiver.
getDescription()
Retrieves the unit's description.
public
getDescription() : string
Return values
string —The unit description.
getName()
Retrieves the unit's name.
public
getName() : string
Return values
string —The unit name.
install()
Installs the unit into the database.
public
install(mixed $corporation) : array<string|int, mixed>
Creates a new NetworkUnit record with the unit's properties and associates it with the given corporation ID. Then, for each dataset configured for the unit, a NetworkDataSetTemplate record is created. Finally, each associated Agent is installed, and their IDs are collected.
Parameters
- $corporation : mixed
-
The corporation ID with which this unit is associated.
Return values
array<string|int, mixed> —An array containing the unit ID, name, description, and installed agents.
pushAgent()
Adds an Agent instance to the unit.
public
pushAgent(Agent $agent) : self
Parameters
- $agent : Agent
-
The agent to add.
Return values
self —Returns the current instance for chaining.
setDefaultReceiver()
Sets the default receiver for the unit.
public
setDefaultReceiver(UnitReceiver $type, string $name) : void
Assigns the default receiver type and name.
Parameters
- $type : UnitReceiver
-
The type of the default receiver.
- $name : string
-
The name of the default receiver.
setDescription()
Sets the unit's description.
public
setDescription(string $set) : self
Parameters
- $set : string
-
The description to assign.
Return values
self —Returns the current instance for chaining.
setName()
Sets the unit's name.
public
setName(string $set) : self
Parameters
- $set : string
-
The name to assign to the unit.
Return values
self —Returns the current instance for chaining.