hasMany(LotteryAward::class, 'lottery_id', 'id'); } public function members() { return $this->hasMany(LotteryMember::class, 'lottery_id', 'id'); } public function winMembers() { return $this->hasMany(LotteryWinMember::class, 'lottery_id', 'id'); } public function scopeKeyword($query) { $keyword = request()->keyword; if ($keyword) { return $query->where('title', 'like', '%'.$keyword.'%'); } return $query; } public function addLotteryable($able) { $this->update(['lotteryable_type'=>$able::class, 'lotteryable_id'=>$able->id]); } public function lotteryable() { return $this->morphTo(); } }