Esempio n. 1
0
 /**
  * Adds meta data
  *
  * @return mixed
  */
 public function addMeta($key, $value)
 {
     $existing = $this->meta()->where('key', $key)->where('value', Helpers::maybeEncode($value))->first();
     if ($existing) {
         return false;
     }
     $meta = $this->meta()->create(['key' => $key, 'value' => $value]);
     return $meta->isSaved() ? $meta : $meta->getErrors();
 }
Esempio n. 2
0
 public function testMaybeDecode()
 {
     $data = ['a' => 'A', 'true' => true];
     $validJson = json_encode($data);
     $actual = Helpers::maybeDecode($validJson);
     $this->assertEquals(json_decode($validJson, false), $actual, 'failed to decode a valid json string');
     $invalidJson = '{a: }';
     $actual = Helpers::maybeDecode($invalidJson);
     $this->assertEquals('{a: }', $actual, 'failed to return invalid json');
     $almostJson = '01.01.1970';
     $actual = Helpers::maybeDecode($almostJson);
     $this->assertEquals('01.01.1970', $actual, 'failed to return almost json');
 }
Esempio n. 3
0
 /**
  * Maybe encode a value for saving
  *
  * @param $value
  * @return null
  */
 public function setValueAttribute($value)
 {
     $this->attributes['value'] = Helpers::maybeEncode($value);
 }