PHP code example of paulhenri-l / laravel-dynamic-attributes
1. Go to this page and download the library: Download paulhenri-l/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/ */
paulhenri-l / laravel-dynamic-attributes example snippets
class Member extends Illuminate\Database\Eloquent\Model
{
use PaulhenriL\LaravelDynamicAttributes\HasDynamicAttributes;
}
class Member extends Illuminate\Database\Eloquent\Model
{
use PaulhenriL\LaravelDynamicAttributes\HasDynamicAttributes;
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->registerDynamicAttribute(
'my_dynamic_attribute',
function ($key) {
return "Trying to get {$key}";
},
function ($key, $value) {
echo "Setting {$key}";
}
);
}
}
$member = new Member();
$member->my_dynamic_attribute = 'Hello';
$member->my_dynamuc_attribute;