master 1
This commit is contained in:
68
src/Meta.php
Normal file
68
src/Meta.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user