You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xshop/app/Models/Prop.php

44 lines
932 B
PHTML

8 months ago
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Translatable\HasTranslations;
8 months ago
class Prop extends Model
{
use HasFactory, HasTranslations, SoftDeletes;
public $translatable = ['label', 'unit'];
protected $casts = [
'dataz',
'optionz'
];
public static $prop_types = ['text', 'number', 'checkbox', 'color', 'select', 'multi', 'singlemulti'];
public function categories()
{
return $this->belongsToMany(Category::class);
}
public function getDatazAttribute()
{
$result = [];
foreach (json_decode($this->options) as $item) {
$result[$item->title] = $item->value;
}
return $result;
}
public function getOptionzAttribute()
{
return json_decode($this->options);
}
8 months ago
}