PHP code example of pwrdk / laravel-custom-attributes

1. Go to this page and download the library: Download pwrdk/laravel-custom-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/ */

    

pwrdk / laravel-custom-attributes example snippets


php artisan:migrate

php artisan db:seed --class="PWRDK\CustomAttributes\Seeds\DatabaseSeeder"

php artisan vendor:publish --provider="PWRDK\CustomAttributes\CustomAttributesServiceProvider"
 php
use PWRDK\CustomAttributes\CustomAttributes;
CustomAttributes::createKey('is_active', 'Is Active', 'boolean', true);
CustomAttributes::createKey('last_seen', 'Last seen', 'datetime', true);
CustomAttributes::createKey('favourite_colours', 'Favourite Colours', 'text', false);
 php
$user->attr()->set('is_active', true);
$user->attr()->set('last_seen', now());
$user->attr()->set('favourite_colours','red');
$user->attr()->set('favourite_colours','green');
$user->attr()->set('favourite_colours','blue');
 php
$user->attr()->unset('is_active');
 php
$user->attr()->update(58, ['value' => 'cyan']);
=> PWRDK\CustomAttributes\Models\AttributeTypes\AttributeTypeDefault {#975
     value: "yellow",
   }
 php
AttributeType::create(['handle' => 'prices', 'display_name' => 'Prices in different currencies']);
 php
class CustomAttribute extends CustomAttributeModel
{
    public function attributeTypeScheduleEventOverlay()
    {
        return $this->hasOne(AttributeTypeScheduleEventOverlay::class);
    }
}
 php
$product = App\Models\Product::find(1000);
$product->attr()->set('prices', ['usd' => 100, 'eur' => 100, 'gbp' => 90, 'jpy' => 10695]);