PHP code example of trexology / extendable

1. Go to this page and download the library: Download trexology/extendable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

trexology / extendable example snippets


'providers' => [
    Trexology\Extendable\Providers\ExtendableServiceProvider::class,
];

php artisan vendor:publish --provider="Trexology\Extendable\Providers\ExtendableServiceProvider"
php artisan migrate

use Trexology\Extendable\Traits\Extendable;
class Article extends \Illuminate\Database\Eloquent\Model {
    use Extendable;
}

return [
    'App\User' => [                                                     // model name
        'gender' => [                                                    // field name
            'title' => 'Gender',                                         // field title (can be used in views)
            'type' => \Trexology\Extendable\CustomFieldType::Radio,     // field type
            'options' => [                                              // possible values/labels
                'male' => 'Male',
                'female' => 'Female'
            ],
            'default' => 'male'                                              // default value
        ]
    ]
];

$data = [
    'title' => 'Awesome Article!!!', // regular field
    'gender' => 'male'               // custom filed     
];

$article = new Article();
$article->fill($data);
$article->save();

$article = Article::find(1);
$article->gender->value; // 1
echo $article->gender;   // 1

$article->customFields; // return collection of custom fields