diff --git a/app/Controllers/HomeController.php b/app/Controllers/HomeController.php index b62eb27..7659f4a 100644 --- a/app/Controllers/HomeController.php +++ b/app/Controllers/HomeController.php @@ -61,6 +61,7 @@ class HomeController extends Controller } $news = DB::table('news_posts') + ->whereNull('deleted_at') ->whereIn('category_id', explode(',', config('general.homepage-news'))) ->limit(3) ->get(); diff --git a/app/Controllers/NewsController.php b/app/Controllers/NewsController.php index ddd1335..12ae25c 100644 --- a/app/Controllers/NewsController.php +++ b/app/Controllers/NewsController.php @@ -42,6 +42,7 @@ class NewsController extends Controller ->get(); $posts = DB::table('news_posts') + ->whereNull('news_posts.deleted_at') ->join('news_categories', function (JoinClause $join) { $join->on('news_posts.category_id', '=', 'news_categories.category_id') ->where('news_categories.category_hidden', '=', 0); diff --git a/app/News/Post.php b/app/News/Post.php index 535b6e0..28354f2 100644 --- a/app/News/Post.php +++ b/app/News/Post.php @@ -130,24 +130,24 @@ class Post */ public function save(): void { - // // Create submission data, insert and update take the same format - // $data = [ - // 'news_category' => $this->category, - // 'user_id' => $this->user, - // 'news_timestamp' => $this->time, - // 'news_title' => $this->title, - // 'news_content' => $this->text, - // ]; + $data = [ + 'category_id' => $this->category->id, + 'user_id' => $this->user->id, + 'post_title' => $this->title, + 'post_text' => $this->text, + ]; - // // Update if id isn't 0 - // if ($this->id) { - // DB::table('news') - // ->where('news_id', $this->id) - // ->update($data); - // } else { - // $this->id = DB::table('news') - // ->insertGetId($data); - // } + // Update if id isn't 0 + if ($this->id) { + $data['updated_at'] = Carbon::now(); + + DB::table('news_posts') + ->where('post_id', $this->id) + ->update($data); + } else { + $this->id = DB::table('news_posts') + ->insertGetId($data); + } } /** @@ -155,11 +155,9 @@ class Post */ public function delete(): void { - // DB::table('news') - // ->where('news_id', $this->id) - // ->delete(); - - // $this->id = 0; + DB::table('news_posts') + ->where('post_id', $this->id) + ->update(['deleted_at' => Carbon::now()]); } /**