<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property mixed id
 */
class Product extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'image','video', 'writer_id', 'writer',
        'category_id',
        'user_id',
        'visit_counts',
        'model_id',
       
    ];

    /**
     * Return descriptions for Product
     * @return HasMany
     */
    public function descriptions() : HasMany
    {
        return $this->hasMany(ProductDescription::class);
    }

    /**
     * Return category for Product
     * @return BelongsTo
     */
    public function category() :BelongsTo
    {
        return $this->belongsTo(Category::class);
    }
public function categories()
    {
        return $this->belongsToMany('App\Category','product_categories','product_id','category_id');
    }
 public function user() :BelongsTo
    {
        return $this->belongsTo(User::class,'user_id')->withTrashed();
    }


    /**
     * Return other photos for Product
     * @return HasMany
     */
    public function photos () :HasMany
    {
        return $this->hasMany(ProductPhoto::class);
    }

}
