diff --git a/app/Model/Categories.php b/app/Model/Categories.php index 448d1175..5b2a42b3 100644 --- a/app/Model/Categories.php +++ b/app/Model/Categories.php @@ -67,7 +67,7 @@ class Categories extends Model /** * Undocumented function. * - * @return void + * @return string */ public function getRouteKeyName() { @@ -101,4 +101,13 @@ public function editor() { return $this->belongsTo(Account::class, 'editor_id', 'id'); } + + /** + * @param string $slug + * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|null|object + */ + public static function firstWhereSlug(string $slug) + { + return self::query()->where('slug', '=', $slug)->first(); + } } diff --git a/app/Model/Concerns/Publishers.php b/app/Model/Concerns/Publishers.php index 0bcea49e..48358bb8 100644 --- a/app/Model/Concerns/Publishers.php +++ b/app/Model/Concerns/Publishers.php @@ -14,19 +14,25 @@ trait Publishers */ public static function bootPublishers() { - if (auth()->check()) { - static::creating(function ($model) { - $model->setAttribute('creator_id', auth()->id()); - $model->setAttribute('editor_id', auth()->id()); - }); + static::creating(function ($model) { + if (auth()->check()) { + $model->fill([ + 'creator_id' => auth()->id(), + 'editor_id' => auth()->id(), + ]); + } + }); - static::deleting(function ($model) { + static::deleting(function ($model) { + if (auth()->check()) { return $model->setAttribute('editor_id', auth()->id()); - }); + } + }); - static::updating(function ($model) { + static::updating(function ($model) { + if (auth()->check()) { return $model->setAttribute('editor_id', auth()->id()); - }); - } + } + }); } } diff --git a/app/Modules/Articles/BackendController.php b/app/Modules/Articles/BackendController.php index 30bb8b7d..94dd1077 100644 --- a/app/Modules/Articles/BackendController.php +++ b/app/Modules/Articles/BackendController.php @@ -2,7 +2,6 @@ namespace App\Modules\Articles; -use App\Modules\Articles\Events\ArticleDeleted; use Carbon\Carbon; use App\Model\Article; use App\Model\Categories; @@ -10,6 +9,7 @@ use App\Modules\ModuleEngine; use App\Classes\Repositories\ArticleRepository; use App\Modules\Articles\Events\ArticleCreated; +use App\Modules\Articles\Events\ArticleDeleted; use App\Modules\Articles\Events\ArticleUpdated; use App\Classes\Repositories\ArticleCategoryRepository; @@ -64,7 +64,7 @@ public function create() * Generate a form for editing or creating a model. * * @param Article $article model to be used. - * @return void + * @return \Illuminate\Contracts\View\View */ public function form(Article $article) { @@ -89,17 +89,6 @@ public function store(Request $request) return redirect()->route('admin.articles.index'); } - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show($id) - { - // - } - /** * Show the form for editing the specified resource. * @@ -148,47 +137,6 @@ public function destroy($slug) return response()->json(['status' => 'true', 'redirect' => route('admin.articles.index')]); } - /** - * Category Index. - * @param ArticleCategoryRepository $categoryRepository - * @return \Illuminate\Contracts\View\View - */ - public function categories(ArticleCategoryRepository $categoryRepository) - { - return $this->make('categories')->with('categories', $categoryRepository->all()); - } - - /** - * @param Request $request - * @return \Illuminate\Http\RedirectResponse - */ - public function categories_store(Request $request) - { - $this->validate($request, ['unique:title']); - - $category = new Categories; - $category->title = $request['name']; - $category->save(); - - return redirect()->route('admin.articles.categories.index'); - } - - /** - * @param int $id - * @param ArticleCategoryRepository $categoryRepository - * @return \Illuminate\Http\RedirectResponse - * - * @throws \Exception - */ - public function categories_destroy(int $id, ArticleCategoryRepository $categoryRepository) - { - $category = $categoryRepository->whereID($id); - - $category->delete(); - - return redirect()->route('admin.articles.categories.index'); - } - /** * Save the data for the menu to the database. * diff --git a/app/Modules/Articles/Blade/categories.blade.php b/app/Modules/Articles/Blade/categories.blade.php index a3664059..fd036140 100644 --- a/app/Modules/Articles/Blade/categories.blade.php +++ b/app/Modules/Articles/Blade/categories.blade.php @@ -19,7 +19,7 @@