From 3136ad33f7464452261ff26e65944c44e0e56b72 Mon Sep 17 00:00:00 2001 From: Luca Patera Date: Fri, 29 Oct 2021 01:58:50 +0200 Subject: [PATCH] Removed type column from chats table --- app/Telegram/Middleware/CollectChat.php | 14 ------------- .../2021_10_29_015610_change_chats_table.php | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 database/migrations/2021_10_29_015610_change_chats_table.php diff --git a/app/Telegram/Middleware/CollectChat.php b/app/Telegram/Middleware/CollectChat.php index e248ec1..b1ba25f 100644 --- a/app/Telegram/Middleware/CollectChat.php +++ b/app/Telegram/Middleware/CollectChat.php @@ -5,7 +5,6 @@ use App\Models\Chat; use Illuminate\Support\Facades\DB; use SergiX44\Nutgram\Nutgram; -use SergiX44\Nutgram\Telegram\Attributes\UpdateTypes; class CollectChat { @@ -19,23 +18,10 @@ public function __invoke(Nutgram $bot, $next): void $chat = DB::transaction(function () use ($user, $bot) { - //get chat type - $type = match ($bot->update()?->getType()) { - UpdateTypes::MESSAGE => $bot->update()->message->chat->type, - UpdateTypes::EDITED_MESSAGE => $bot->update()->edited_message->chat->type, - UpdateTypes::INLINE_QUERY, UpdateTypes::CALLBACK_QUERY => 'private', - default => 'unknown', - }; - - if ($type === 'unknown') { - info('unknown', [$bot->update()]); - } - //save or update chat $chat = Chat::updateOrCreate([ 'chat_id' => $user->id, ], [ - 'type' => $type, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'username' => $user->username, diff --git a/database/migrations/2021_10_29_015610_change_chats_table.php b/database/migrations/2021_10_29_015610_change_chats_table.php new file mode 100644 index 0000000..1dbcdff --- /dev/null +++ b/database/migrations/2021_10_29_015610_change_chats_table.php @@ -0,0 +1,21 @@ +dropColumn('type'); + }); + } + + public function down(): void + { + Schema::table('chats', function (Blueprint $table) { + $table->string('type'); + }); + } +};