ironshark / laravel-extendable
Traits for Laravel to add and manage custom Eloquent model fields.
Installs: 11 034
Dependents: 0
Suggesters: 0
Security: 0
Stars: 24
Watchers: 11
Forks: 6
Open Issues: 1
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-12-21 19:10:34 UTC
README
How to install
Composer Install
composer require ironshark/laravel-extendable
Laravel Service Provider
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
Usage
Add traits
Add model trait to models, where you want to use custom fields.
class Article extends \Illuminate\Database\Eloquent\Model { use IronShark\Extendable\ModelTrait; }
Config fields
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/retrieve customfield values
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