<?php

namespace Tps\Shops\Models;

use Model;

/**
 * Model
 */
class Category extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\Sortable;

    public $implement = ['RainLab.Translate.Behaviors.TranslatableModel'];
    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;

    /**
     * @var string The database table used by the model.
     */
    public $table = 'tps_shops_categories';

    /**
     * @var array Validation rules
     */
    public $rules = [];

    public $hasMany = [
        'shops' => [
            'Tps\Shops\Models\Shop',
        ]
    ];

    public $belongsTo = [
        'top_category' => [
            'Tps\Shops\Models\TopCategory',
        ],
    ];

    public $translatable = ['name'];

    public function getShops(){
        return Shop::where('category_id', $this->id)->limit(6)->get();
    }

    public function getTopCategoryFieldAttribute() {
        return $this->top_category->name;
    }

}
