You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB

<?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;
class Meta extends Model
{
protected $fillable = ['meta', 'uuid'];
function read( $key ){
$meta = unserialize( $this->meta );
return $meta[ $key ];
}
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');
}
}