From e193132773b7dbd2176e48195ab769e19a802f8e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 19 Dec 2024 09:29:38 -0700 Subject: [PATCH] Add Comment --- app/Models/Comment.php | 55 +++++++++++++++++++ ...024_03_28_105059_create_comments_table.php | 41 ++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 app/Models/Comment.php create mode 100644 database/migrations/2024_03_28_105059_create_comments_table.php diff --git a/app/Models/Comment.php b/app/Models/Comment.php new file mode 100644 index 0000000..2c077f5 --- /dev/null +++ b/app/Models/Comment.php @@ -0,0 +1,55 @@ + + */ + protected function casts(): array + { + return [ + 'entities' => 'array', + 'likes' => 'integer', + 'replies' => 'integer', + 'can_reply' => 'boolean', + 'is_pinned' => 'boolean', + 'is_edited' => 'boolean', + 'is_hidden' => 'boolean', + 'is_sensitive' => 'boolean', + ]; + } + + public function profile(): BelongsTo + { + return $this->belongsTo(Profile::class); + } + + public function shareUrl(): string + { + return "c:id:1"; + } + + public function video() + { + return $this->belongsTo(Video::class); + } +} diff --git a/database/migrations/2024_03_28_105059_create_comments_table.php b/database/migrations/2024_03_28_105059_create_comments_table.php new file mode 100644 index 0000000..9b9236b --- /dev/null +++ b/database/migrations/2024_03_28_105059_create_comments_table.php @@ -0,0 +1,41 @@ +bigIncrements('id'); + $table->unsignedBigInteger('video_id')->index(); + $table->unsignedBigInteger('profile_id'); + $table->text('caption')->nullable(); + $table->json('entities')->nullable(); + $table->unsignedInteger('likes')->default(0); + $table->unsignedInteger('replies')->default(0); + $table->boolean('can_reply')->default(true); + $table->boolean('is_pinned')->default(false); + $table->boolean('is_edited')->default(false); + $table->boolean('is_hidden')->default(false); + $table->boolean('is_sensitive')->default(false); + + $table->foreign('video_id')->references('id')->on('videos')->cascadeOnDelete(); + $table->foreign('profile_id')->references('id')->on('profiles')->cascadeOnDelete(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('comments'); + } +};