Package Data | |
---|---|
Maintainer Username: | TUNER88 |
Maintainer Contact: | pauli@ironshark.de (Anton Pauli) |
Package Create Date: | 2015-07-24 |
Package Last Update: | 2016-07-12 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:06:51 |
Package Statistics | |
---|---|
Total Downloads: | 11,033 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 24 |
Total Watchers: | 11 |
Total Forks: | 6 |
Total Open Issues: | 1 |
composer require ironshark/laravel-extendable
Add service provider in app/config/app.php
'providers' => [
IronShark\Extendable\ExtendableServiceProvider::class,
];
Publish configs, templates and run migrations.
php artisan vendor:publish --provider="IronShark\Extendable\ExtendableServiceProvider"
php artisan migrate
Add model trait to models, where you want to use custom fields.
class Article extends \Illuminate\Database\Eloquent\Model {
use IronShark\Extendable\ModelTrait;
}
Use app/config/custom-fields.php
to configure your fields.
return [
'App\Room' => [ // model name
'light' => [ // field name
'title' => 'Light', // field title (can be used in views)
'type' => \IronShark\Extendable\CustomFieldType::Radio, // field type
'options' => [ // possible values/labels
0 => 'Off',
1 => 'On'
],
'default' => 1 // default value
]
]
];
Assign custom field values as regular values.
$data = [
'title' => 'Awesome Article!!!', // regular field
'recomended' => 1 // custom filed
];
$article = new Article();
$article->fill($data);
$article->save();
Retrieve custom field values.
$article = Article::find(1);
$article->recomended->value; // 1
echo $article->recomended; // 1
| FieldType | DB DataType | Example |
|---------------------------|--------------|-----------------------|
| CustomFieldType::String | VARCHAR(255) | Lorem
|
| CustomFieldType::Text | TEXT | Lorem Ipsum...
|
| CustomFieldType::Select | VARCHAR(255) | en_us
|
| CustomFieldType::Radio | VARCHAR(255) | off
|
| CustomFieldType::Checkbox | VARCHAR(255) | 0
|
| CustomFieldType::DateTime | TIMESTAMP | 2015-01-19 03:14:07
|