| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Models; |
| 4 |
|
| 5 |
use FluentCommunity\App\Functions\Utility; |
| 6 |
|
| 7 |
/** |
| 8 |
* Meta Model - DB Model for Meta table |
| 9 |
* |
| 10 |
* Database Model |
| 11 |
* |
| 12 |
* @package FluentCommunity\App\Models |
| 13 |
* |
| 14 |
* @version 1.0.0 |
| 15 |
* |
| 16 |
* @property int $id |
| 17 |
* @property string|null $object_type |
| 18 |
* @property int|null $object_id |
| 19 |
* @property string|null $meta_key |
| 20 |
* @property mixed $value |
| 21 |
*/ |
| 22 |
class Meta extends Model |
| 23 |
{ |
| 24 |
protected $table = 'fcom_meta'; |
| 25 |
|
| 26 |
protected $primaryKey = 'id'; |
| 27 |
|
| 28 |
protected $guarded = ['id']; |
| 29 |
|
| 30 |
protected $fillable = [ |
| 31 |
'object_type', |
| 32 |
'object_id', |
| 33 |
'meta_key', |
| 34 |
'value' |
| 35 |
]; |
| 36 |
|
| 37 |
public function setValueAttribute($value) |
| 38 |
{ |
| 39 |
$this->attributes['value'] = maybe_serialize($value); |
| 40 |
} |
| 41 |
|
| 42 |
public function getValueAttribute($value) |
| 43 |
{ |
| 44 |
return Utility::safeUnserialize($value); |
| 45 |
} |
| 46 |
|
| 47 |
public function scopeByType($query, $type) |
| 48 |
{ |
| 49 |
return $query->where('object_type', $type); |
| 50 |
} |
| 51 |
|
| 52 |
public function scopeByMetaKey($query, $key) |
| 53 |
{ |
| 54 |
return $query->where('meta_key', $key); |
| 55 |
} |
| 56 |
|
| 57 |
public function scopeByObjectId($query, $objectId) |
| 58 |
{ |
| 59 |
return $query->where('object_id', $objectId); |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|