Add Comment
This commit is contained in:
parent
69d7bccca7
commit
e193132773
55
app/Models/Comment.php
Normal file
55
app/Models/Comment.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Concerns\HasSnowflakePrimary;
|
||||||
|
use App\Services\HashidService;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class Comment extends Model
|
||||||
|
{
|
||||||
|
use HasFactory, HasSnowflakePrimary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the IDs are auto-incrementing.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attributes that should be cast.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('comments', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user