feat: bot
This commit is contained in:
+22
-3
@@ -8,7 +8,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
class User extends Authenticatable
|
||||
{
|
||||
protected $fillable = [
|
||||
'username', 'password', 'status', 'comment', 'chat_id', 'bot_token',
|
||||
'username', 'password', 'status', 'comment', 'chat_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -42,9 +42,28 @@ class User extends Authenticatable
|
||||
return $this->hasMany(Channel::class, 'user_id');
|
||||
}
|
||||
|
||||
public function hasTelegramChat(): bool
|
||||
{
|
||||
return trim((string) ($this->chat_id ?? '')) !== '';
|
||||
}
|
||||
|
||||
/** @deprecated Use hasTelegramChat(); kept for existing call sites. */
|
||||
public function hasTelegramBot(): bool
|
||||
{
|
||||
return trim((string) ($this->bot_token ?? '')) !== ''
|
||||
&& trim((string) ($this->chat_id ?? '')) !== '';
|
||||
return $this->hasTelegramChat();
|
||||
}
|
||||
|
||||
public static function findEnabledByChatId(int|string|null $chatId): ?self
|
||||
{
|
||||
$chatId = trim((string) $chatId);
|
||||
if ($chatId === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return static::query()
|
||||
->where('status', 1)
|
||||
->where('chat_id', $chatId)
|
||||
->orderBy('id')
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user