30 lines
787 B
PHP
30 lines
787 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Category extends BaseModel
|
|
{
|
|
//
|
|
public static function getType($type){
|
|
return self::where('type',$type)->where('is_checked',1)->orderBy('sort','desc')->orderBy('id','desc')->pluck('name','id');
|
|
}
|
|
public static function getTypeKey($type,$key=''){
|
|
$arr= self::where('type',$type)->where('is_checked',1)->get()->toArray();
|
|
if($key)
|
|
{
|
|
return data_to_key($arr,$key);
|
|
}
|
|
return $arr;
|
|
}
|
|
public function getContent(){
|
|
return $this->hasOne('App\Models\Article','category_id','id');
|
|
}
|
|
public function getTypeNameAttribute()
|
|
{
|
|
$arr= config('adconfig.category_group');
|
|
return $arr[$this->type];
|
|
}
|
|
}
|