From effd0203a3bc1c1219a1692c80a7f0d7ea65169a Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Thu, 21 Mar 2024 00:47:41 +0100 Subject: [PATCH] feat: Add Streamer and StreamerPanel controllers, Streamer model - Added StreamerController with index and show methods - Added StreamerPanelController with index, create, store, edit, update, and destroy methods - Created Streamer model with fillable attributes and platform-specific URL generation logic - Implemented migration for creating the streamers table --- app/Http/Controllers/StreamerController.php | 25 ++++++++ .../Controllers/StreamerPanelController.php | 57 +++++++++++++++++++ app/Models/Streamer.php | 42 ++++++++++++++ ...24_03_20_233357_create_streamers_table.php | 31 ++++++++++ 4 files changed, 155 insertions(+) create mode 100644 app/Http/Controllers/StreamerController.php create mode 100644 app/Http/Controllers/StreamerPanelController.php create mode 100644 app/Models/Streamer.php create mode 100644 database/migrations/2024_03_20_233357_create_streamers_table.php diff --git a/app/Http/Controllers/StreamerController.php b/app/Http/Controllers/StreamerController.php new file mode 100644 index 0000000..789e9d2 --- /dev/null +++ b/app/Http/Controllers/StreamerController.php @@ -0,0 +1,25 @@ +belongsTo(Champion::class); + } + + public function getPlatformAttribute($value): string + { + $platforms = [ + 'twitch' => 'Twitch', + 'youtube' => 'YouTube', + 'kick' => 'Kick', + 'douyu' => 'Douyu', + 'huya' => 'Huya', + ]; + + return $platforms[$value]; + } + + public function getStreamerUrlAttribute(): string + { + return match ($this->platform) { + 'Twitch' => "https://www.twitch.tv/{$this->username}", + 'YouTube' => "https://www.youtube.com/@{$this->username}", + 'Kick' => "https://kick.com/{$this->username}", + 'Douyu' => "https://www.douyu.com/{$this->username}", + 'Huya' => "https://www.huya.com/{$this->username}", + }; + } +} diff --git a/database/migrations/2024_03_20_233357_create_streamers_table.php b/database/migrations/2024_03_20_233357_create_streamers_table.php new file mode 100644 index 0000000..a69f5d8 --- /dev/null +++ b/database/migrations/2024_03_20_233357_create_streamers_table.php @@ -0,0 +1,31 @@ +id(); + $table->foreignId('champion_id')->constrained(); + $table->enum('platform', ['twitch', 'youtube', 'kick', 'douyu', 'huya']); + $table->string('username'); + $table->string('displayname'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('streamers'); + } +};