ExpinBot/.svn/pristine/04/04b3365ffc3692436379f267a07...

50 lines
1.4 KiB
Plaintext
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class tg_group extends Model{
public $incrementing = false; // Telegram 的 chat_id 是 bigint可為負數
protected $keyType = 'string';
protected $fillable = [
'chat_id',
'type',
'title',
'creator',
'description',
'invite_link',
'photo_small_file_id',
'photo_big_file_id',
];
protected $casts = [
'chat_id' => 'integer',
'type' => 'string',
'title' => 'string',
'username' => 'string',
'description' => 'string',
'invite_link' => 'string',
'photo_small_file_id' => 'string',
'photo_big_file_id' => 'string',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
public static function updateOrCreateFromTelegram(array $chatData): self
{
return self::updateOrCreate(
['chat_id' => $chatData['id']],
[
'type' => $chatData['type'] ?? null,
'title' => $chatData['title'] ?? null,
'creator' => $chatData['creator'] ?? null,
'invite_link' => $chatData['invite_link'] ?? null,
'photo_small_file_id' => $chatData['photo']['small_file_id'] ?? null,
'photo_big_file_id' => $chatData['photo']['big_file_id'] ?? null,
]
);
}
}