Skip to content

Commit 2beff02

Browse files
committed
🗃️ ajout d'une migration pour le champ published_at dans la table aricles
1 parent e489863 commit 2beff02

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

app/Models/Article.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
4949
'declined_at',
5050
'shared_at',
5151
'sponsored_at',
52+
'published_at',
5253
];
5354

5455
/**
@@ -62,6 +63,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
6263
'declined_at' => 'datetime',
6364
'shared_at' => 'datetime',
6465
'sponsored_at' => 'datetime',
66+
'published_at' => 'datetime',
6567
'show_toc' => 'boolean',
6668
'is_pinned' => 'boolean',
6769
];
@@ -150,6 +152,11 @@ public function sponsoredAt(): ?Carbon
150152
return $this->sponsored_at;
151153
}
152154

155+
public function publishedAt(): ?Carbon
156+
{
157+
return $this->published_at;
158+
}
159+
153160
public function isSubmitted(): bool
154161
{
155162
return ! $this->isNotSubmitted();
@@ -249,7 +256,8 @@ public function scopeAwaitingApproval(Builder $query): Builder
249256

250257
public function scopePublished(Builder $query): Builder
251258
{
252-
return $query->submitted()
259+
return $query->whereDate('published_at', '<=', now())
260+
->submitted()
253261
->approved();
254262
}
255263

@@ -258,6 +266,7 @@ public function scopeNotPublished(Builder $query): Builder
258266
return $query->where(function ($query) {
259267
$query->whereNull('submitted_at')
260268
->orWhereNull('approved_at')
269+
->orWhereNull('published_at')
261270
->orWhereNotNull('declined_at');
262271
});
263272
}
@@ -300,14 +309,14 @@ public function scopeNotDeclined(Builder $query): Builder
300309
public function scopeRecent(Builder $query): Builder
301310
{
302311
return $query->orderBy('is_pinned', 'desc')
303-
->orderBy('submitted_at', 'desc');
312+
->orderBy('published_at', 'desc');
304313
}
305314

306315
public function scopePopular(Builder $query): Builder
307316
{
308317
return $query->withCount('reactions')
309318
->orderBy('reactions_count', 'desc')
310-
->orderBy('submitted_at', 'desc');
319+
->orderBy('published_at', 'desc');
311320
}
312321

313322
public function scopeTrending(Builder $query): Builder
@@ -316,7 +325,7 @@ public function scopeTrending(Builder $query): Builder
316325
$query->where('created_at', '>=', now()->subWeek());
317326
}])
318327
->orderBy('reactions_count', 'desc')
319-
->orderBy('submitted_at', 'desc');
328+
->orderBy('published_at', 'desc');
320329
}
321330

322331
public function markAsShared()
@@ -328,15 +337,15 @@ public static function nextForSharing(): ?self
328337
{
329338
return self::notShared()
330339
->published()
331-
->orderBy('submitted_at', 'asc')
340+
->orderBy('published_at', 'asc')
332341
->first();
333342
}
334343

335344
public static function nexForSharingToTelegram(): ?self
336345
{
337346
return self::published()
338347
->whereNull('tweet_id')
339-
->orderBy('submitted_at', 'asc')
348+
->orderBy('published_at', 'asc')
340349
->first();
341350
}
342351

app/Models/User.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia
4949
'last_login_at',
5050
'last_login_ip',
5151
'email_verified_at',
52+
'published_at',
5253
'opt_in',
5354
];
5455

@@ -295,7 +296,7 @@ public function delete()
295296
parent::delete();
296297
}
297298

298-
public function scopeHasActivity(Builder $query)
299+
public function scopeHasActivity(Builder $query): Builder
299300
{
300301
return $query->where(function ($query) {
301302
$query->has('threads')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('articles', function (Blueprint $table) {
17+
$table->after('user_id', function ($table) {
18+
$table->timestamp('published_at')->nullable();
19+
});
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::table('articles', function (Blueprint $table) {
31+
$table->removeColumn('published_at');
32+
});
33+
}
34+
};

0 commit comments

Comments
 (0)