62 lines
1.1 KiB
PHP
62 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Traits\ReadAll;
|
|
use Overtrue\LaravelFollow\Traits\CanBeFavorited;
|
|
|
|
class Policy extends Model
|
|
{
|
|
use CanBeFavorited, ReadAll;
|
|
|
|
protected $dates = [
|
|
'begined_at',
|
|
'ended_at',
|
|
];
|
|
|
|
/**
|
|
* 所属部门
|
|
* @return [type] [description]
|
|
*/
|
|
public function category()
|
|
{
|
|
return $this->belongsTo(Category::class)->withDefault();
|
|
}
|
|
|
|
/**
|
|
* 所属行业
|
|
* @return [type] [description]
|
|
*/
|
|
public function trades()
|
|
{
|
|
return $this->belongsToMany(Trade::class, 'policy_trades')->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* 所属地区
|
|
* @return [type] [description]
|
|
*/
|
|
public function areas()
|
|
{
|
|
return $this->belongsToMany(ChinaArea::class, 'policy_areas')->withTimestamps();
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function getTradeTitleAttribute()
|
|
{
|
|
$trades = $this->trades()->get();
|
|
$title = [];
|
|
foreach ($trades as $key => $trade) {
|
|
$title[] = $trade->title;
|
|
}
|
|
|
|
return implode(" ", $title);
|
|
|
|
}
|
|
|
|
}
|