gruene-seele/app/Models/ProductCategory.php
2022-01-18 18:30:14 +01:00

58 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use App\Services\Type;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\ProductCategory
*
* @property int $id
* @property int $product_id
* @property int $category_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Category $category
* @property-read \App\Models\Product $product
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory whereCategoryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory whereProductId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory whereUpdatedAt($value)
* @mixin \Eloquent
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductCategory query()
*/
class ProductCategory extends Model
{
protected $table = 'product_categories';
protected $casts = [
'show_on' => 'array',
];
protected $fillable = [
'pos', 'product_id', 'category_id', 'show_on'
];
public function product()
{
return $this->belongsTo('App\Models\Product', 'product_id');
}
public function category()
{
return $this->belongsTo('App\Models\Category', 'category_id');
}
public function getShowOnTypes(){
$ret = [];
foreach($this->show_on as $show){
$ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-';
}
return $ret;
}
}