<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Moderator extends BaseModel
{
    use HasFactory;

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

    public function scopeStatus($query)
    {
        $status = request()->status;
        if (is_numeric($status)) {
            return $query->where('status', $status);
        }
        return $query;
    }
}
