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); } }