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

55 lines
1.2 KiB
PHTML

7 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;
7 months ago
class Prop extends Model
{
use HasFactory, HasTranslations, SoftDeletes;
public $translatable = ['label', 'unit'];
protected $casts = [
'dataz',
'optionz',
'datas'
];
public static $prop_types = ['text', 'number', 'checkbox', 'color', 'select', 'multi', 'singlemulti', 'date', 'time'];
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 getDatasAttribute()
{
$result = [];
foreach (json_decode($this->options) as $item) {
$result[$item->value] = $item->title;
}
return $result;
}
public function getOptionzAttribute()
{
return json_decode($this->options);
}
7 months ago
}