<?php

namespace Database;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;

class Inviteuser extends Model
{
    protected $table = 'inviteuser';

    public static function getInvits($chatid)
    {
        return DB::table('inviteuser')->where('chatid', (string)$chatid)->get();
    }

    public static function getCountInvits($chatid)
    {
        return DB::table('inviteuser')->select('id')->where('chatid', (string)$chatid)->count();
    }

    public static function hasInvited($chatid, $userid)
    {
        return DB::table('inviteuser')->select('id')->where('chatid', (string)$chatid)->where('userid',(string)$userid)->exists();
    }

    public static function addInvited($chatid, $userid)
    {
        return DB::table('inviteuser')->insertGetId(['chatid' => (string)$chatid,'userid'=>(string)$userid]);
    }
}
