@@ -14,17 +14,20 @@ final class UpdateArticle
1414
1515 private $ body ;
1616
17+ private $ shouldBePublished ;
18+
1719 private $ originalUrl ;
1820
1921 private $ tags ;
2022
2123 private $ series ;
2224
23- public function __construct (Article $ article , string $ title , string $ body , array $ options = [])
25+ public function __construct (Article $ article , string $ title , string $ body , bool $ shouldBePublished , array $ options = [])
2426 {
2527 $ this ->article = $ article ;
2628 $ this ->title = $ title ;
2729 $ this ->body = $ body ;
30+ $ this ->shouldBePublished = $ shouldBePublished ;
2831 $ this ->originalUrl = $ options ['original_url ' ] ?? null ;
2932 $ this ->tags = $ options ['tags ' ] ?? [];
3033 $ this ->series = $ options ['series ' ] ?? null ;
@@ -36,6 +39,7 @@ public static function fromRequest(Article $article, ArticleRequest $request): s
3639 $ article ,
3740 $ request ->title (),
3841 $ request ->body (),
42+ $ request ->shouldBePublished (),
3943 [
4044 'original_url ' => $ request ->originalUrl (),
4145 'tags ' => $ request ->tags (),
@@ -51,6 +55,7 @@ public function handle(): Article
5155 'body ' => $ this ->body ,
5256 'original_url ' => $ this ->originalUrl ,
5357 'slug ' => $ this ->title ,
58+ 'published_at ' => $ this ->shouldBePublished ? now () : null ,
5459 ]);
5560 $ this ->article ->syncTags ($ this ->tags );
5661 $ this ->article ->updateSeries (Series::find ($ this ->series ));
0 commit comments