76 lines
1.5 KiB
PHP
76 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: garrett
|
|
* Date: 4/17/16
|
|
* Time: 11:59 AM
|
|
*/
|
|
|
|
namespace Glmdev\Meta;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Glmdev\Foundation\FoundationModel;
|
|
|
|
class Meta extends Model implements FoundationModel
|
|
{
|
|
|
|
protected $fillable = ['meta', 'uuid'];
|
|
|
|
function read( $key ){
|
|
$meta = unserialize( $this->meta );
|
|
if ( array_key_exists( $key, $meta ) ){
|
|
return $meta[ $key ];
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function write( $key, $value ){
|
|
$meta = unserialize( $this->meta );
|
|
$meta[ $key ] = $value;
|
|
$meta = serialize( $meta );
|
|
$this->meta = $meta;
|
|
$this->save();
|
|
}
|
|
|
|
function readRaw(){
|
|
return $this->meta;
|
|
}
|
|
|
|
function writeRaw( $serialized ){
|
|
$this->meta = $serialized;
|
|
$this->save();
|
|
}
|
|
|
|
public function getUUID(){
|
|
return $this->uuid;
|
|
}
|
|
|
|
public function setUuid(){
|
|
// check if UUID is set
|
|
if( !isset($this->uuid) || is_null($this->uuid) || $this->uuid === "" ){
|
|
$this->uuid = Uuid::uuid4();
|
|
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function rawUuid( Uuid $uuid ){
|
|
$this->uuid = $uuid;
|
|
$this->save();
|
|
}
|
|
|
|
public static function formTable( Blueprint $table ){
|
|
$table->uuid('uuid');
|
|
$table->text('meta');
|
|
}
|
|
|
|
public static function route(){}
|
|
|
|
} |