Package Data | |
---|---|
Maintainer Username: | isaacqc |
Maintainer Contact: | beschi.jacopo@gmail.com (Jacopo Beschi) |
Package Create Date: | 2015-02-12 |
Package Last Update: | 2017-07-31 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:03:38 |
Package Statistics | |
---|---|
Total Downloads: | 12 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
#Laravel-Single-Table-Inheritance
Mapping domain model into relational database is hard. For this reason there are many ways to do that. Single table inheritance is one of them. the stengths of this approach are:
Laravel-Single-Table-Inheritance is a package that offer a simple and basic model to handle single table inheritance with eloquent ORM. Be aware this pattern come from Martin Fowler(Patterns of Enterprise Application Architecture). For more information follow this link: Single Table Inheritance. Also check my post about Single table inheritance.
##Installation with Composer
To install Laravel-Single-Table-Inheritance with Composer, add this line to your composer.json file in the `require field:
"jacopo/laravel-single-table-inheritance": "1.0.*"
Congratulations! You succesfully installed the package.
##Usage
To use the package you need to extend Jacopo\LaravelSingleTableInheritance\Models\Model
on your model class. Then you need to change the following attributes of your model:
The field $table_type
contains the string that will be saved in the $table_type_field
column to distinguish the current model to the other models saved in the table. The field $my_attributes
is an array that contains all the attributes that belongs to the current model(except the eloquent attributes created_at updated_at and deleted_at which are auto setted). For a better understanding on how to setup your model you should definatelly look in the examples folder.
Keep in mind that each model can fetch the data only from the rows that belongs to his type even if all data is stored and the same table! You can only set and get attributes related to the current model and his parents. If you want to fetch all the data inside the table you should create custom queries.