首次提交 Laravel 專案
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as BaseKernel;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
/**
|
||||
* 全局中间件
|
||||
*/
|
||||
protected $middleware = [
|
||||
// 你可以在这里加全局中间件
|
||||
];
|
||||
|
||||
/**
|
||||
* 路由中间件群组
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class tg_chats extends Model{
|
||||
protected $primaryKey = 'chat_id';
|
||||
public $incrementing = false; // Telegram 的 chat_id 是 bigint,可為負數
|
||||
protected $keyType = 'string';
|
||||
protected $fillable = [
|
||||
'chat_id',
|
||||
'type',
|
||||
'title',
|
||||
'username',
|
||||
'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,
|
||||
'username' => $chatData['username'] ?? 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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user