mirror of
https://github.com/archtechx/laravel-tips.git
synced 2025-12-12 05:14:04 +00:00
Weekly Thread command
This commit is contained in:
parent
faefe1c45b
commit
3fe86bed08
3 changed files with 80 additions and 5 deletions
|
|
@ -40,12 +40,15 @@ class Thread extends Model
|
|||
|
||||
public static function booted()
|
||||
{
|
||||
static::creating(fn (self $model) => $model->created_at ??= now());
|
||||
static::creating(static function (self $model) {
|
||||
$model->created_at ??= now();
|
||||
$model->links ??= [];
|
||||
});
|
||||
}
|
||||
|
||||
public function tips(): HasMany
|
||||
{
|
||||
return $this->hasMany(Tip::class);
|
||||
return $this->hasMany(Tip::class, 'thread_slug');
|
||||
}
|
||||
|
||||
public function author(): BelongsTo
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Tip extends Model
|
|||
$table->string('slug')->unique();
|
||||
$table->string('title');
|
||||
$table->string('tweet_id');
|
||||
$table->foreignId('thread_slug')->nullable();
|
||||
$table->string('thread_slug')->nullable();
|
||||
$table->foreignId('author_username')->constrained('authors', 'username');
|
||||
$table->json('images')->default('[]');
|
||||
$table->timestamp('created_at');
|
||||
|
|
@ -87,9 +87,9 @@ class Tip extends Model
|
|||
|
||||
public static function booted()
|
||||
{
|
||||
static::creating(function (self $model) {
|
||||
static::creating(static function (self $model) {
|
||||
$model->created_at ??= now();
|
||||
$model->slug ??= $this->defaultSlug();
|
||||
$model->slug ??= $model->defaultSlug();
|
||||
});
|
||||
|
||||
static::addGlobalScope('order', fn (Builder $query) => $query->orderBy('created_at', 'desc'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue