reimplemented management functionality
This commit is contained in:
parent
ceab147eb3
commit
2e7f22c7d6
3 changed files with 22 additions and 22 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue