<?php

namespace App\Models;

use App\Exports\RegularActivityMemberExport;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class RegularActivityOrder extends BaseModel
{
    use HasFactory;

    public $fillable = ['user_id', 'activity_id', 'name', 'mobile','is_apply_food'];

    public function scopeKeyword($query)
    {
        $keyword = request()->keyword;
        if ($keyword) return $query->whereHas("user", function ($sql) use($keyword) {
            $sql->where('name', "like", "%{$keyword}%")
                ->orWhere("mobile", "like", "%{$keyword}%");
        });
        return $query;
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function activityMember()
    {
        return $this->hasOne(RegularActivityMember::class, 'user_id', 'user_id');
    }

    public function agentUser()
    {
        return $this->hasOne(AgentUser::class, 'user_id', 'user_id');
    }
}
