<?php

namespace App\Modules\Book\Models;

use Illuminate\Database\Eloquent\Model;

class BookCategory extends Model
{
    protected $table = 'book_categories';
    protected $fillable = ['id','category_name','pid','channel_name'];

    public static function getTopCategories(){
        //return self::select('channel_name')->groutBy('channel_name')->get();
    }

    public static function getSecondCategories($id_arr=[]){
        if($id_arr){
            return self::select('id','category_name','channel_name')->where('pid','!=',0)->whereIn('id',$id_arr)->get();
        }
        return self::select('id','category_name','channel_name')->where('pid','!=',0)->get();
    }

    public static function getSecondCategoriesId($chanel_name){
        $res = self::where('pid','!=',0)->where('channel_name','=',$chanel_name)->select('id')->get();
        $id = [];
        foreach ($res as $v){
            $id[] = $v->id;
        }
        return $id;
    }



}
