Getting Started
To get started, add the Fusion\Concerns\HasExtension
trait to the Model file you wish to extend. The trait will include helper methods for pulling the extending Field data.
<?php
namespace Modules\Acme\Models;
use Fusion\Concerns\HasExtension;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use HasExtension;
...
}
Next, run the fusion:sync
command to register your Extension(s). This command will generate the necessary storage for storing the extending fields.
php artisan fusion:sync
Assigning a Fieldset
You should now see your Model listed in the Configure > Extensions interface where you can assign a Fieldset. This will generate the extending Fields.
Retrieving Fields
You can access the Fieldset
and Fields
, respectively:
// Returns \Fusion\Models\Fieldset
$fieldset = $model->fieldset;
// Returns Collection of \Fusion\Models\Field
$fields = $model->fields;
Saving
HasExtension
registers a saved
event listener that will listen for Model events for saving the extending Fieldset.
Important: Laravel's Model Events only fire if the Model recieves an update, therefore it may be necessary to at least run
$model->touch()
for everyPATCH
request to assure is fired.