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