<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SubCategory extends Model
{
    use SoftDeletes;
    protected $dates = ['deleted_at'];
    protected $table = 'sub_categories';
    protected $primaryKey = 'sub_category_id';
    protected $fillable = [
        'category_id',
        'sub_category_name',
        'sub_category_description',
        'sub_category_slug',
        'image',
        'active_status',
    ];
    protected $hidden = [
        'created_at',
        'updated_at',
        'deleted_at'
    ];


    public function productLists() {
        return $this->hasMany('App\Models\Products', 'sub_category_id', 'sub_category_id')->where('active_status', 1)->orderBy('product_id', 'desc');
    }
    public function productsImages() {
        return $this->hasMany('App\Models\ProductsImage', 'product_id', 'product_id')->where('active_status',1)->orderBy('products_image_id', 'desc');
  }


    public function categoryList() {
        return $this->hasMany('App\Models\Category', 'category_id', 'category_id');
    }

    public function subcategorylist() {
        return $this->hasMany('App\Models\SubCategory', 'sub_category_id', 'sub_category_id')->where('active_status', 1)->orderBy('category_id', 'desc');
    }

    public function subCategoriesImages() {
        return $this->hasMany('App\Models\SubCategoriesImage', 'sub_category_id', 'sub_category_id')->where('active_status',1);
    }

    //   For products Images Nithish
    public function products() {
        return $this->hasMany('App\Models\Products','sub_category_id', 'sub_category_id')->where('active_status', 1);
    }
    public function productimages() {
        return $this->hasMany('App\Models\ProductsImage', 'product_id', 'product_id')->where('active_status', 1)->orderBy('products_image_id', 'desc');
    }
 
}
