Models
Models are responsible for representing the data of the application and providing an abstraction for interacting with that data. They encapsulate the business logic and rules associated with the data, as well as facilitate the communication with the underlying database.
To generate new models, you may use the apiato:generate:model interactive command:
php artisan apiato:generate:model
Definition & Principles
Read Porto SAP Documentation (#Models).
Rules
- All Models:
- MUST be placed in the
app/Containers/{Section}/{Container}/Modelsdirectory. - MUST extend the
App\Ship\Parents\Models\Modelclass.- The parent extension SHOULD be aliased as
ParentModel.
- The parent extension SHOULD be aliased as
- MUST be placed in the
- All User Models MUST extend the
App\Ship\Parents\Models\UserModelclass.- The parent extension SHOULD be aliased as
ParentUserModel.
- The parent extension SHOULD be aliased as
Folder Structure
app
└── Containers
└── Section
└── Container
└── Models
├── Model.php
└── ...
Code Example
Models are defined exactly as you would define them in Laravel.
Model Trait
If your model does not extend the App\Ship\Parents\Models\Model or the App\Ship\Parents\Models\UserModel class,
it is essential to incorporate the ModelTrait trait into your model.
By doing so, your model will benefit from various functionalities provided by the trait,
such as hash ids and other features necessary for proper integration with the framework.
use Apiato\Core\Traits\ModelTrait;
class Demo
{
use ModelTrait;
...
}