Models
#
Definition & PrinciplesRead Porto SAP Documentation (#Models).
#
Rules- All Models MUST extend from
App\Ship\Parents\Models\Model
. - If the name of a model differs from the Container name you have to implement
model()
method in the repository - more details.
#
Folder Structure - App - Containers - {section-name} - {container-name} - Models - User.php - UserId.php - ...
#
Code Sampleclass Demo extends Model{ protected $table = 'demos';
protected $fillable = [ 'label', 'user_id' ];
protected $hidden = [ 'token', ];
protected $casts = [ 'total_credits' => 'float', ];
protected $dates = [ 'created_at', 'updated_at', ];
public function user() { return $this->belongsTo(\App\Containers\AppSection\User\Models\User::class); }}
Notice the Demo Model has a relationship with User Model, which lives in another Container.
#
CastsThe casts attribute can be used to parse any of the model's attributes to a specific type. In the code sample below we can cast total_credits
to float
.
More information about the applicable cast-types can be found in the laravel eloquent-mutators documentation.
You can place any dates inside the $dates
to parse those automatically.