PHP code example of aw-studio / laravel-dynamic-attributes

1. Go to this page and download the library: Download aw-studio/laravel-dynamic-attributes 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/ */

    

aw-studio / laravel-dynamic-attributes example snippets


composer 

php artisan vendor:publish --tag="dynamic-attributes:migrations"

use Illuminate\Database\Eloquent\Model;
use AwStudio\DynamicAttributes\HasDynamicAttributes;

class Page extends Model
{
    use HasDynamicAttributes;
}

$page = Page::create([
    'headline' => 'Hello World!',
    'text'     => 'Lorem Ipsum...',
]);

echo $page->headline; // "Hello World!"

Page::create(['released_at' => now()->addWeek()]);

dd($page->released_at); // Is an instance of Illuminate\Support\Carbon

$page = Page::create(['is_active' => 1]);

dump($page->is_active); // output: 1

$page->setDynamicAttributeCast('is_active', 'boolean')->save();

dd($page->is_active); // output: true

Page::whereAttribute('foo', 'bar');