<?php

namespace App\Models;
use App\User;
use Packages\Product\Models\Product;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model
{
    protected $fillable = ['title', 'parent', 'category_type', 'creator_id', 'slug', 'discription'];


    use SoftDeletes;


    public function user()
    {
        return $this->belongsTo(User::class, 'creator_id', 'id');
    }


    public function products()
    {
        return $this->morphedByMany(Product::class, 'categorizable');
    }
    public function getCategoryTypeAttribute($value)
    {

        switch ($value) {
            case 0:
                $category_type = 'محصولات';
                break;
            case 1:
                $category_type = 'اخبار';
                break;
            case 2:
                $category_type = 'مطالب';
                break;

            default:
                $category_type = '';

        }
        return $category_type;
    }


}
