From d001b44e8f51d2cdfa39bf0b87bd50e48a71204e Mon Sep 17 00:00:00 2001 From: K Muller Date: Wed, 7 Jan 2026 11:20:27 +0100 Subject: [PATCH] feat: :sparkles: add newsTag model / morphMany table pivot --- app/Http/Controllers/Back/NewsController.php | 9 +- .../Controllers/Back/NewsTagController.php | 206 ++++++++++++++++++ app/Http/Middleware/HandleInertiaRequests.php | 6 + .../Requests/Back/News/StoreNewsRequest.php | 4 +- .../Back/NewsTag/StoreNewsTagRequest.php | 45 ++++ .../Back/NewsTag/UpdateNewsTagRequest.php | 17 ++ app/Models/News.php | 42 ++-- app/Models/NewsCategory.php | 10 +- app/Models/NewsTag.php | 66 ++++++ app/Policies/NewsTagPolicy.php | 112 ++++++++++ database/factories/NewsCategoryFactory.php | 1 - database/factories/NewsTagFactory.php | 25 +++ ...26_01_07_100655_create_news_tags_table.php | 65 ++++++ ...26_01_07_100655_create_newsables_table.php | 107 +++++++++ database/seeders/NewsTagSeeder.php | 17 ++ lang/en/back.php | 3 + lang/en/models.php | 1 + lang/en/validation.php | 3 + lang/fr/back.php | 3 + lang/fr/models.php | 1 + lang/fr/validation.php | 3 + .../ts/back/Components/Layout/AppSidebar.tsx | 9 + resources/ts/back/Pages/News/Form.tsx | 77 ++++--- resources/ts/back/Pages/News/Show.tsx | 15 ++ resources/ts/back/Pages/NewsCategory/Form.tsx | 16 -- .../ts/back/Pages/NewsCategory/Index.tsx | 27 +-- resources/ts/back/Pages/NewsCategory/Show.tsx | 17 -- resources/ts/back/Pages/NewsTag/Create.tsx | 58 +++++ resources/ts/back/Pages/NewsTag/Edit.tsx | 61 ++++++ resources/ts/back/Pages/NewsTag/Form.tsx | 103 +++++++++ resources/ts/back/Pages/NewsTag/Index.tsx | 182 ++++++++++++++++ resources/ts/back/Pages/NewsTag/Show.tsx | 123 +++++++++++ resources/ts/back/types/global.d.ts | 17 +- .../components/front/sections/news.blade.php | 8 +- .../views/front/pages/news/show.blade.php | 8 +- routes/web-back.php | 13 ++ 36 files changed, 1363 insertions(+), 117 deletions(-) create mode 100644 app/Http/Controllers/Back/NewsTagController.php create mode 100644 app/Http/Requests/Back/NewsTag/StoreNewsTagRequest.php create mode 100644 app/Http/Requests/Back/NewsTag/UpdateNewsTagRequest.php create mode 100644 app/Models/NewsTag.php create mode 100644 app/Policies/NewsTagPolicy.php create mode 100644 database/factories/NewsTagFactory.php create mode 100644 database/migrations/2026_01_07_100655_create_news_tags_table.php create mode 100644 database/migrations/2026_01_07_100655_create_newsables_table.php create mode 100644 database/seeders/NewsTagSeeder.php create mode 100644 resources/ts/back/Pages/NewsTag/Create.tsx create mode 100644 resources/ts/back/Pages/NewsTag/Edit.tsx create mode 100644 resources/ts/back/Pages/NewsTag/Form.tsx create mode 100644 resources/ts/back/Pages/NewsTag/Index.tsx create mode 100644 resources/ts/back/Pages/NewsTag/Show.tsx diff --git a/app/Http/Controllers/Back/NewsController.php b/app/Http/Controllers/Back/NewsController.php index 8d046847..9bbf5fe5 100644 --- a/app/Http/Controllers/Back/NewsController.php +++ b/app/Http/Controllers/Back/NewsController.php @@ -7,6 +7,7 @@ use App\Http\Requests\Back\News\StoreNewsRequest; use App\Http\Requests\Back\News\UpdateNewsRequest; use App\Models\News; use App\Models\NewsCategory; +use App\Models\NewsTag; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Inertia\Inertia; @@ -82,6 +83,7 @@ class NewsController extends Controller 'data' => CommonResource::make($news), 'enumNewsStatus' => NewsStatusEnum::toArray(), 'newsCategory' => NewsCategory::getModelsCached(), + 'newsTag' => NewsTag::getModelsCached(), 'modelName' => $this->modelName, ]); } @@ -95,7 +97,7 @@ class NewsController extends Controller public function show(News $news): \Inertia\Response { return Inertia::render('News/Show', [ - 'data' => CommonResource::make($news->load('categories')), + 'data' => CommonResource::make($news->load('categories', 'tags')), 'enumNewsStatus' => NewsStatusEnum::toArray(), 'modelName' => $this->modelName, ]); @@ -115,6 +117,7 @@ class NewsController extends Controller if ($newsModel->saveOrFail()) { $newsModel->categories()->syncWithoutDetaching($request->input('categories', [])); + $newsModel->tags()->syncWithoutDetaching($request->input('tags', [])); return redirect()->route("back.$this->modelName.edit", $newsModel); } return redirect()->route("back.$this->modelName.create"); @@ -130,9 +133,10 @@ class NewsController extends Controller public function edit(News $news): \Inertia\Response { return Inertia::render('News/Edit', [ - 'data' => CommonResource::make($news->load('categories')), + 'data' => CommonResource::make($news->load('categories', 'tags')), 'enumNewsStatus' => NewsStatusEnum::toArray(), 'newsCategory' => NewsCategory::getModelsCached(), + 'newsTag' => NewsTag::getModelsCached(), 'modelName' => $this->modelName, ]); } @@ -150,6 +154,7 @@ class NewsController extends Controller $news->inertiaFill($request->validated()); if ($news->saveOrFail()) { $news->categories()->sync($request->input('categories', [])); + $news->tags()->sync($request->input('tags', [])); return redirect()->route("back.$this->modelName.edit", $news); } return redirect()->route("back.$this->modelName.edit", $news); diff --git a/app/Http/Controllers/Back/NewsTagController.php b/app/Http/Controllers/Back/NewsTagController.php new file mode 100644 index 00000000..dea35790 --- /dev/null +++ b/app/Http/Controllers/Back/NewsTagController.php @@ -0,0 +1,206 @@ +authorizeResource(NewsTag::class); + } + + /** + * Display a listing of the resource. + * + * @param \Illuminate\Http\Request $request + * @return \Inertia\Response + */ + public function index(Request $request): \Inertia\Response + { + /** @var \Illuminate\Database\Eloquent\Builder<\App\Models\News> $query */ + $query = NewsTag::query()->withCount('news'); + + if ($request->routeIs("back.$this->modelName.trash")) { + $query = $query->onlyTrashed(); + } + + /** @var string $search Search field */ + $search = $request->search; + if ($search) { + $this->searchQuery( + $query, + $search, + null, + 'name', + ); + } + $searchFields = \implode(', ', [ + trans('validation.attributes.name'), + ]); + + /** Sort columns with a query */ + $this->sortQuery($query); + + /** Custom pagination */ + $newsTagModels = $this->paginate($query); + + return Inertia::render('NewsTag/Index', [ + 'newsTagModels' => CommonResource::collection($newsTagModels), + 'search' => $search, + 'searchFields' => $searchFields, + 'modelName' => $this->modelName, + ]); + } + + /** + * Show the form for creating a new resource. + * + * @param \App\Models\News $news_tag + * @return \Inertia\Response + */ + public function create(NewsTag $news_tag): \Inertia\Response + { + return Inertia::render('NewsTag/Create', [ + 'data' => CommonResource::make($news_tag), + 'modelName' => $this->modelName, + ]); + } + + /** + * Show a specific resource. + * + * @param \App\Models\NewsTag $news_tag + * @return \Inertia\Response + */ + public function show(NewsTag $news_tag): \Inertia\Response + { + $news = $news_tag->news()->paginate(12); + return Inertia::render('NewsTag/Show', [ + 'data' => CommonResource::make($news_tag), + 'news' => CommonResource::collection($news), + 'enumNewsStatus' => NewsStatusEnum::toArray(), + 'modelName' => $this->modelName, + ]); + } + + /** + * Store a newly created resource. + * + * @param \App\Http\Requests\Back\NewsTag\StoreNewsTagRequest $request + * @return \Illuminate\Http\RedirectResponse + */ + public function store(StoreNewsTagRequest $request): \Illuminate\Http\RedirectResponse + { + return DB::transaction(function () use ($request) { + $newsModel = new NewsTag(); + $newsModel->fill($request->validated()); + if ($newsModel->saveOrFail()) { + return redirect()->route("back.$this->modelName.edit", $newsModel); + } + return redirect()->route("back.$this->modelName.create"); + }); + } + + /** + * Show the form for editing the specified resource. + * + * @param \App\Models\NewsTag $news_tag + * @return \Inertia\Response + */ + public function edit(NewsTag $news_tag): \Inertia\Response + { + return Inertia::render('NewsTag/Edit', [ + 'data' => CommonResource::make($news_tag), + 'modelName' => $this->modelName, + ]); + } + + /** + * Update the specified resource. + * + * @param \App\Http\Requests\Back\News\UpdateNewsTagRequest $request + * @param \App\Models\NewsTag $news_tag + * @return \Illuminate\Http\RedirectResponse + */ + public function update(UpdateNewsTagRequest $request, NewsTag $news_tag): \Illuminate\Http\RedirectResponse + { + return DB::transaction(function () use ($request, $news_tag) { + $news_tag->fill($request->validated()); + if ($news_tag->saveOrFail()) { + return redirect()->route("back.$this->modelName.edit", $news_tag); + } + return redirect()->route("back.$this->modelName.edit", $news_tag); + }); + } + + /** + * Restore the specified resource. + * + * @param integer $news_tag + * @return \Illuminate\Http\RedirectResponse + */ + public function restore(int $news_tag): \Illuminate\Http\RedirectResponse + { + $news_tag = NewsTag::withTrashed()->findOrFail($news_tag); + /** @var array */ + $previousQueries = []; + \parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries); + if ($news_tag->restore()) { + return redirect()->route("back.$this->modelName.trash", $previousQueries); + } + return redirect()->back(); + } + + /** + * Destroy the specified resource. + * + * @param \App\Models\NewsTag $news_tag + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(NewsTag $news_tag): \Illuminate\Http\RedirectResponse + { + /** @var array */ + $previousQueries = []; + \parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries); + if ($news_tag->delete()) { + return redirect()->route("back.$this->modelName.index", $previousQueries); + } + return redirect()->back(); + } + + /** + * Destroy the specified resource. + * + * @param \App\Models\NewsTag|integer $news_tag + * @return \Illuminate\Http\RedirectResponse + */ + public function forceDestroy(NewsTag|int $news_tag): \Illuminate\Http\RedirectResponse + { + if (is_int($news_tag)) { + $news_tag = NewsTag::withTrashed()->findOrFail($news_tag); + } + /** @var array */ + $previousQueries = []; + \parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries); + if ($news_tag->forceDelete()) { + return redirect()->route("back.$this->modelName.trash", $previousQueries); + } + return redirect()->back(); + } +} diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index b325d586..f371e796 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -15,6 +15,7 @@ use App\Models\DocumentTag; use App\Models\DynamicPage; use App\Models\News; use App\Models\NewsCategory; +use App\Models\NewsTag; use App\Models\PageConfig; use Diglactic\Breadcrumbs\Breadcrumbs; use Illuminate\Http\Request; @@ -95,6 +96,11 @@ class HandleInertiaRequests extends Middleware 'viewTrash' => Gate::allows('viewTrash', NewsCategory::class), 'create' => Gate::allows('create', NewsCategory::class), ], + "newsTags" => [ + 'viewAny' => Gate::allows('viewAny', NewsTag::class), + 'viewTrash' => Gate::allows('viewTrash', NewsTag::class), + 'create' => Gate::allows('create', NewsTag::class), + ], 'companies' => [ 'viewAny' => Gate::allows('viewAny', Company::class), 'viewTrash' => Gate::allows('viewTrash', Company::class), diff --git a/app/Http/Requests/Back/News/StoreNewsRequest.php b/app/Http/Requests/Back/News/StoreNewsRequest.php index 36766de0..b5d7d9ed 100644 --- a/app/Http/Requests/Back/News/StoreNewsRequest.php +++ b/app/Http/Requests/Back/News/StoreNewsRequest.php @@ -71,7 +71,9 @@ class StoreNewsRequest extends FormRequest 'content' => ['required', 'string', new WysiwygLength(10, 5000)], 'status' => ['required', new Enum(NewsStatusEnum::class)], 'categories' => 'nullable|array', - 'categories.*' => 'integer|exists:news,id', + 'categories.*' => 'integer|exists:news_categories,id', + 'tags' => 'nullable|array', + 'tags.*' => 'integer|exists:news_tags,id', 'published_at' => 'nullable|date', 'unpublished_at' => 'nullable|date|after:published_at', 'inverted' => 'boolean', diff --git a/app/Http/Requests/Back/NewsTag/StoreNewsTagRequest.php b/app/Http/Requests/Back/NewsTag/StoreNewsTagRequest.php new file mode 100644 index 00000000..26df0007 --- /dev/null +++ b/app/Http/Requests/Back/NewsTag/StoreNewsTagRequest.php @@ -0,0 +1,45 @@ +|string> + */ + public function rules(): array + { + return [ + 'slug' => 'required|string|between:3,255', + 'name' => 'required|string|between:3,255', + 'color' => 'required|string|hex_color', + ]; + } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes(): array + { + return [ + 'name' => trans('validation.custom.name'), + 'color' => trans('validation.custom.color'), + ]; + } +} diff --git a/app/Http/Requests/Back/NewsTag/UpdateNewsTagRequest.php b/app/Http/Requests/Back/NewsTag/UpdateNewsTagRequest.php new file mode 100644 index 00000000..836ca7e3 --- /dev/null +++ b/app/Http/Requests/Back/NewsTag/UpdateNewsTagRequest.php @@ -0,0 +1,17 @@ +route('news_tag')); + } + +} diff --git a/app/Models/News.php b/app/Models/News.php index 60f28535..f7b9994c 100644 --- a/app/Models/News.php +++ b/app/Models/News.php @@ -50,7 +50,7 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable public function getRouteKeyName(): string { - return 'slug'; + return request()->routeIs('back.*') ? 'id' : 'slug'; } public function getLocalizedRouteKey($locale) @@ -168,7 +168,7 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable public function inertiaFill(array $attributes) { - $attributes = Arr::except($attributes, ['categories']); + $attributes = Arr::except($attributes, ['categories', 'tags']); $this->traitInertiaFill($attributes); } @@ -256,12 +256,12 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable * * @return string|null */ - public function getCategoryLabelsAttribute(): ?string + public function getTagLabelsAttribute(): ?string { - if (empty($this->categories)) { + if (empty($this->tags)) { return null; } - $labels = collect($this->categories) + $labels = collect($this->tags) ->map(fn($cat) => $cat->name ?? null) ->filter() ->values(); @@ -271,14 +271,14 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable /** * Get data related to the first category of this news item. * - * @return NewsCategory|null + * @return NewsTag|null */ - public function getFirstCategoryDataAttribute(): ?NewsCategory + public function getFirstTagDataAttribute(): ?NewsTag { - if (empty($this->categories) || empty($this->categories[0])) { + if (empty($this->tags) || empty($this->tags[0])) { return null; } - return $this->categories[0]; + return $this->tags[0]; } /** @@ -305,21 +305,37 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable */ public function categories(): BelongsToMany { - return $this->belongsToMany( + return $this->morphedByMany( NewsCategory::class, - 'news_category_pivot', + 'newsable', + 'newsables', 'news_id', - 'category_id' + 'newsable_id' ); } + /** + * The relation with NewsTag. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function tags(): BelongsToMany + { + return $this->morphedByMany( + NewsTag::class, + 'newsable', + 'newsables', + 'news_id', + 'newsable_id' + )->withTimestamps(); + } public static function getPublishedNewsInCurrentLocale() { $locale = App::getLocale(); // ici mettre le cache avec la relation catégorie return News::query() - ->with('categories') + ->with('categories', 'tags') ->whereNotNull("slug->$locale"); } } diff --git a/app/Models/NewsCategory.php b/app/Models/NewsCategory.php index b6523a11..435e3413 100644 --- a/app/Models/NewsCategory.php +++ b/app/Models/NewsCategory.php @@ -16,7 +16,6 @@ use Uwil\LaravelActivityLogs\Traits\ActivityLog; /** * @property int $news_id News focused. * @property string $name Name of the category. - * @property string $color Color of the category * @property-read \Illuminate\Support\Carbon $created_at Date on which the news was created. * @property-read \Illuminate\Support\Carbon $updated_at Date on which the news was updated. */ @@ -88,11 +87,12 @@ class NewsCategory extends Model implements TranslatableModel */ public function news(): BelongsToMany { - return $this->belongsToMany( + return $this->morphToMany( News::class, - 'news_category_pivot', - 'category_id', - 'news_id' + 'newsable', + 'newsables', + 'news_id', + 'newsable_id' ); } } diff --git a/app/Models/NewsTag.php b/app/Models/NewsTag.php new file mode 100644 index 00000000..a239b36d --- /dev/null +++ b/app/Models/NewsTag.php @@ -0,0 +1,66 @@ + + */ + protected $fillable = [ + 'name', + 'slug', + 'color' + ]; + + /** + * The translatable columns. + * + * @var list + */ + public $translatable = [ + 'name', + 'slug' + ]; + + /** + * Relation to Document + * + * @return BelongsToMany + */ + public function news(): BelongsToMany + { + return $this->morphToMany( + News::class, + 'newsable', + 'newsables', + 'newsable_id', + 'news_id' + ); + } +} + diff --git a/app/Policies/NewsTagPolicy.php b/app/Policies/NewsTagPolicy.php new file mode 100644 index 00000000..5fd74a78 --- /dev/null +++ b/app/Policies/NewsTagPolicy.php @@ -0,0 +1,112 @@ + $this->faker->unique()->word(), "slug" => $this->faker->unique()->word(), - "color" => "#fff" ]; } } diff --git a/database/factories/NewsTagFactory.php b/database/factories/NewsTagFactory.php new file mode 100644 index 00000000..02fb2cfa --- /dev/null +++ b/database/factories/NewsTagFactory.php @@ -0,0 +1,25 @@ + + */ +class NewsTagFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + "name" => $this->faker->unique()->word(), + "slug" => $this->faker->unique()->word(), + "color" => "#fff" + ]; + } +} diff --git a/database/migrations/2026_01_07_100655_create_news_tags_table.php b/database/migrations/2026_01_07_100655_create_news_tags_table.php new file mode 100644 index 00000000..3403dd57 --- /dev/null +++ b/database/migrations/2026_01_07_100655_create_news_tags_table.php @@ -0,0 +1,65 @@ +id(); + $table->string('name')->comment('Name of the news tag.'); + $table->string('slug')->comment('Slug of the news tag.'); + $table->string('color')->default("#ff4e4e")->comment('Color of the news tag.'); + $table->softDeletes(); + $table->timestamps(); + }); + + // News has now meta categories, then the old news categories were in fact tags. + // We need to put the old categories into tags + $categories = \DB::table('news_categories')->get(); + foreach ($categories as $category) { + \DB::table('news_tags')->insert([ + 'name' => $category->name, + 'slug' => $category->slug, + 'color' => $category->color ?? '#ff4e4e', + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + + // then a new table 'newsables' will be used to store pivot between categories and tags + // then all the old news categories pivot will be passed into the newsables + add as tags model + // at this moment we can delete the old categories to pass the good data + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + $categories = \DB::table('news_tags')->get(); + + foreach ($categories as $category) { + \DB::table('news_categories')->insert([ + 'name' => $category->name, + 'slug' => $category->slug, + 'color' => $category->color ?? '#ff4e4e', + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + + Schema::dropIfExists('news_tags'); + } +}; diff --git a/database/migrations/2026_01_07_100655_create_newsables_table.php b/database/migrations/2026_01_07_100655_create_newsables_table.php new file mode 100644 index 00000000..2fac1b6e --- /dev/null +++ b/database/migrations/2026_01_07_100655_create_newsables_table.php @@ -0,0 +1,107 @@ +id(); + + $table->unsignedBigInteger('news_id'); + $table->unsignedBigInteger('newsable_id'); + $table->string('newsable_type'); + $table->foreign('news_id') + ->references('id')->on('news') + ->onDelete('cascade'); + $table->timestamps(); + + $table->index(['newsable_id', 'newsable_type']); + }); + + + // all the pivot between old categories and news should be store as tags now + $oldCategoriesPivot = \DB::table('news_category_pivot')->get(); + foreach ($oldCategoriesPivot as $catPivot) { + \DB::table('newsables')->insert([ + 'news_id' => $catPivot->news_id, + 'newsable_id' => $catPivot->category_id, + 'newsable_type' => NewsTag::class, + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + + DB::table('news_categories')->delete(); + + // supprimer le champs color + + Schema::table('news_categories', function (Blueprint $table) { + $table->dropColumn('color'); + }); + + $newTrueCategories = [ + [ + "fr" => "Actualités", + "en" => "News", + ], + [ + "fr" => "Espace press", + "en" => "Press space" + ], + ]; + + $categoryMap = []; + + foreach ($newTrueCategories as $index => $cats) { + app()->setLocale('fr'); + + $catModel = NewsCategory::create([ + 'name' => $cats['fr'], + 'slug' => Str::slug($cats['fr']), + ]); + + $categoryMap[$index + 1] = $catModel->id; + + foreach ($cats as $locale => $cat) { + if ($locale === 'fr') continue; + if( $locale === "color") continue; + app()->setLocale($locale); + + $catModel->update([ + 'name' => $cat, + 'slug' => Str::slug($cat), + ]); + } + } + + Schema::drop('news_category_pivot'); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('newsables'); + + Schema::table('news_categories', function (Blueprint $table) { + $table->string('color') + ->default('#ff4e4e') + ->comment('Color of the news category.'); + }); + } +}; diff --git a/database/seeders/NewsTagSeeder.php b/database/seeders/NewsTagSeeder.php new file mode 100644 index 00000000..3e979239 --- /dev/null +++ b/database/seeders/NewsTagSeeder.php @@ -0,0 +1,17 @@ +create(); + } +} diff --git a/lang/en/back.php b/lang/en/back.php index acac7169..60eb7d48 100644 --- a/lang/en/back.php +++ b/lang/en/back.php @@ -247,6 +247,9 @@ return [ "news" => [ "categories" => [ "placeholder" => "select your article's categories" + ], + "tags" => [ + "placeholder" => "select your article's tags" ] ], ]; diff --git a/lang/en/models.php b/lang/en/models.php index 3a2894d1..5865c8a4 100644 --- a/lang/en/models.php +++ b/lang/en/models.php @@ -16,5 +16,6 @@ return [ "document-tag" => "document tag|document tags", "document-category" => "document category|document categories", "document-exercice" => "document exercice|document exercices", + "news-tag" => "news tag|news tag", ], ]; diff --git a/lang/en/validation.php b/lang/en/validation.php index 84368cef..46d99792 100644 --- a/lang/en/validation.php +++ b/lang/en/validation.php @@ -281,5 +281,8 @@ return [ "newsCategory" => [ "news" => "associated news" ], + "news" => [ + "tag" => "etiquette|etiquettes", + ] ], ]; diff --git a/lang/fr/back.php b/lang/fr/back.php index c4e9aa90..c0807425 100644 --- a/lang/fr/back.php +++ b/lang/fr/back.php @@ -248,6 +248,9 @@ return [ "news" => [ "categories" => [ "placeholder" => "sélectionnez les catégories de votre article", + ], + "tags" => [ + "placeholder" => "sélectionnez les étiquettes de votre article", ] ], ]; diff --git a/lang/fr/models.php b/lang/fr/models.php index 9e718cb6..d8181f21 100644 --- a/lang/fr/models.php +++ b/lang/fr/models.php @@ -16,5 +16,6 @@ return [ "document-tag" => "étiquette de document|étiquettes de document", "document-category" => "catégorie de document|catégories de document", "document-exercice" => "exercice de document|exercices de document", + "news-tag" => "étiquette d'actualité|étiquettes d'actualité", ], ]; diff --git a/lang/fr/validation.php b/lang/fr/validation.php index 5de03029..81e87aac 100644 --- a/lang/fr/validation.php +++ b/lang/fr/validation.php @@ -278,6 +278,9 @@ return [ ], "newsCategory" => [ "news" => "actualité(s) associée(s)" + ], + "news" => [ + "tag" => "étiquette|étiquettes", ] ], ]; diff --git a/resources/ts/back/Components/Layout/AppSidebar.tsx b/resources/ts/back/Components/Layout/AppSidebar.tsx index 351b2a4d..432ebf0c 100644 --- a/resources/ts/back/Components/Layout/AppSidebar.tsx +++ b/resources/ts/back/Components/Layout/AppSidebar.tsx @@ -164,6 +164,15 @@ export default function AppSidebar() { .value()} /> ), + authPolicies.newsTags.viewAny && ( + + ), ] }) }, diff --git a/resources/ts/back/Pages/News/Form.tsx b/resources/ts/back/Pages/News/Form.tsx index 152cf45d..26367320 100644 --- a/resources/ts/back/Pages/News/Form.tsx +++ b/resources/ts/back/Pages/News/Form.tsx @@ -22,7 +22,7 @@ import SimpleVimeoId from "@/back/Components/Inputs/SimpleVimeoId"; import { mapLaravelEnumOptions } from "@/lib/mapEnumOptions"; import { cn } from "@/lib/utils"; import { Methods } from "@/lib/enums"; -import { AppEnv, DynamicFieldTypes, LaravelEnum, NewsCategoryModel, NewsModel } from "@/back/types/global"; +import { AppEnv, DynamicFieldTypes, LaravelEnum, NewsCategoryModel, NewsModel, NewsTagModel } from "@/back/types/global"; import useTrans from "@/hooks/use-translations"; import str from "@/hooks/use-string"; import { useCrudSubmit } from "@/hooks/use-crud-submit"; @@ -47,13 +47,14 @@ export default function Form({ const [isGif, setIsGif] = useState(false); const [dynamicKey, setDynamicKey] = useState(null); const enumDynamicFieldTypes = usePage().props.enumDynamicFieldTypes as DynamicFieldTypes; + const newsTag = usePage().props.newsTag as NewsTagModel[]; const newsCategory = usePage().props.newsCategory as NewsCategoryModel[]; const enumNewsStatus = usePage().props.enumNewsStatus as LaravelEnum; - // const { options, defaultValue } = mapLaravelEnumOptions(enumNewsCategory, model?.categories, "category"); - const { options, defaultValue } = mapPivotOptions(newsCategory, model?.categories, "name", locale); - + const { options: optionTags, defaultValue: defaultValueTags } = mapPivotOptions(newsTag, model?.tags, "name", locale); + const { options: optionCategories, defaultValue: defaultValueCategories } = mapPivotOptions(newsCategory, model?.categories, "name", locale); + console.log({defaultValueCategories, defaultValueTags, model}) function isFile(value: unknown): value is File { return value instanceof File; } @@ -73,7 +74,8 @@ export default function Form({ picture: model?.picture, picture_alt: model?.picture_alt ? model?.picture_alt[locale] : "", picture_title: model?.picture_title ? model?.picture_title[locale] : "", - categories: model?.categories ? defaultValue : [], + tags: model?.tags ? defaultValueTags : [], + categories: model?.categories ? defaultValueCategories : [], published_at: model?.published_at ? model?.published_at : null, unpublished_at: model?.unpublished_at ? model?.unpublished_at : null }); @@ -375,27 +377,50 @@ export default function Form({ value={data.content} setData={setData} /> - +
+ + +
{ + if (!value || value.length === 0) return null; + return ( +
+ {value.map((item, i) => ( + + ))} +
+ ); + } + }, { accessorKey: "created_at", diff --git a/resources/ts/back/Pages/NewsCategory/Form.tsx b/resources/ts/back/Pages/NewsCategory/Form.tsx index c614a317..0a20a37e 100644 --- a/resources/ts/back/Pages/NewsCategory/Form.tsx +++ b/resources/ts/back/Pages/NewsCategory/Form.tsx @@ -11,7 +11,6 @@ import useTrans from "@/hooks/use-translations"; import str from "@/hooks/use-string"; import { useCrudSubmit } from "@/hooks/use-crud-submit"; import SubmitButton from "@/back/Components/SubmitButton"; -import SimpleColorPicker from "@/back/Components/Inputs/SimpleColorPicker"; import Slugifycator from "@/back/Components/Inputs/Slugifycator"; export default function Form({ @@ -34,7 +33,6 @@ export default function Form({ _method: method === Methods.POST ? 'post' : 'put', name: model?.name ? model?.name[locale] : "", slug: model?.slug ? model?.slug[locale] : "", - color: model?.color ? model?.color : "" }); const submit = useCrudSubmit({ @@ -75,20 +73,6 @@ export default function Form({ targetValue={data.name} setData={setData} /> -
diff --git a/resources/ts/back/Pages/NewsCategory/Index.tsx b/resources/ts/back/Pages/NewsCategory/Index.tsx index 3c37b563..95e2a1ea 100644 --- a/resources/ts/back/Pages/NewsCategory/Index.tsx +++ b/resources/ts/back/Pages/NewsCategory/Index.tsx @@ -5,7 +5,6 @@ import { AlertCircleIcon, ArchiveIcon, ArrowLeftIcon, Plus } from "lucide-react" import { Row } from "@tanstack/react-table"; // * Components shadcn import { Badge } from "@/components/ui/badge"; -import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; // * Other import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout"; @@ -17,11 +16,9 @@ import InputError from "@/back/Components/InputError"; import { Views } from "@/lib/utils"; import { useFormatedDate } from "@/hooks/use-formated-value"; import { - AppEnv, AuthProp, NewsCategoryModel, Resource, - TranslationField, } from "@/back/types/global"; import str from "@/hooks/use-string"; import useTrans from "@/hooks/use-translations"; @@ -38,9 +35,8 @@ export default function Index({ searchFields: string; modelName: string; }) { - const { auth, appEnv } = usePage().props as unknown as { + const { auth } = usePage().props as unknown as { auth: AuthProp; - appEnv: AppEnv; }; const { viewAny, viewTrash, create } = auth.policies.newsCategories; const isArchiveRoute = route().current(`back.${modelName}.trash`); @@ -68,27 +64,6 @@ export default function Index({ ) }, }, - { - accessorKey: "color", - header: ({ column }: { column: { id: string } }) => ( - - ), - cell: ({ row }: { row: Row }) => { - return ( - - -
-
- {row.getValue("color")} -
- ) - }, - }, { accessorKey: "news", header: () => ( diff --git a/resources/ts/back/Pages/NewsCategory/Show.tsx b/resources/ts/back/Pages/NewsCategory/Show.tsx index 7b00454c..fe159aa9 100644 --- a/resources/ts/back/Pages/NewsCategory/Show.tsx +++ b/resources/ts/back/Pages/NewsCategory/Show.tsx @@ -21,7 +21,6 @@ import str from "@/hooks/use-string"; import useTrans from "@/hooks/use-translations"; import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; import { ArrowLeft } from "lucide-react"; -import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import AssociatedNewsList from "@/back/Components/AssociatedNewsList"; import { renderTranslationCell } from "@/lib/translationCellFallback"; @@ -58,22 +57,6 @@ export default function Show({ data, modelName, news }: { data: SingleResource, ? value[appEnv.locale] : (

{useTrans('back.table_not_known')}

), }, - { - accessorKey: "color", - header: str(useTrans("validation.custom.color")).ucFirst().value(), - cell: ({ value }: { value: string }) => { - return ( - - -
-
- {value} -
- ) - } - }, { accessorKey: "created_at", header: str(useTrans("validation.attributes.created_at")).ucFirst().value(), diff --git a/resources/ts/back/Pages/NewsTag/Create.tsx b/resources/ts/back/Pages/NewsTag/Create.tsx new file mode 100644 index 00000000..53a3ec39 --- /dev/null +++ b/resources/ts/back/Pages/NewsTag/Create.tsx @@ -0,0 +1,58 @@ +// * Packages +import { usePage } from "@inertiajs/react"; +import { route } from "ziggy-js"; +import { ArrowLeft } from "lucide-react"; +// * Other +import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout"; +import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; +import useTrans from "@/hooks/use-translations"; +import { Actions, Methods } from "@/lib/enums"; +import { + AuthProp, + NewsTagModel, + SingleResource, +} from "@/back/types/global"; +import Form from "./Form"; +import str from "@/hooks/use-string"; + +export default function Create({ data, modelName }: { data: SingleResource, modelName: string }) { + const { viewAny } = (usePage().props.auth as AuthProp).policies.newsTags; + const newsTagModel = data.data as NewsTagModel; + const singularModelName = str(modelName).singular().value(); + const transTitle = useTrans("crud.helpers.creation_model", + { + params: { + model: useTrans(`models.classes.${singularModelName}`, { + choice: 1, + }), + }, + }, + ); + + const beforeNode = () => { + return viewAny && ( +
+ } + tooltipContent={

{useTrans("back.crud_back_to_list")}

} + /> +
+ ); + }; + + return ( + +
+ + ); +} diff --git a/resources/ts/back/Pages/NewsTag/Edit.tsx b/resources/ts/back/Pages/NewsTag/Edit.tsx new file mode 100644 index 00000000..526d5f8e --- /dev/null +++ b/resources/ts/back/Pages/NewsTag/Edit.tsx @@ -0,0 +1,61 @@ +// * Packages +import { usePage } from "@inertiajs/react"; +import { route } from "ziggy-js"; +// * Other +import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout"; +import ModelActions from "@/back/Components/ModelActions"; +import useTrans from "@/hooks/use-translations"; +import { Actions, Methods } from "@/lib/enums"; +import Form from "./Form"; +import { Views } from "@/lib/utils"; +import { AuthProp, NewsTagModel, SingleResource } from "@/back/types/global"; +import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; +import { ArrowLeft } from "lucide-react"; +import str from "@/hooks/use-string"; + +export default function Edit({ data, modelName }: { data: SingleResource, modelName: string }) { + const { viewAny } = (usePage().props.auth as AuthProp).policies.newsTags; + const newsTagModel = data.data as NewsTagModel; + const actionModels = [ + Views.VISUALIZATION, + Views.DUPLICATION, + Views.ARCHIVATION, + ]; + const singularModelName = str(modelName).singular().value(); + const transTitle = useTrans("crud.helpers.edition_model", { + params: { model: useTrans(`models.classes.${singularModelName}`, { choice: 1 }) }, + }); + + const beforeNode = () => { + return viewAny && ( +
+ } + tooltipContent={

{useTrans("back.crud_back_to_list")}

} + /> +
+ ); + }; + + return ( + + + + + ); +} diff --git a/resources/ts/back/Pages/NewsTag/Form.tsx b/resources/ts/back/Pages/NewsTag/Form.tsx new file mode 100644 index 00000000..9b3717f7 --- /dev/null +++ b/resources/ts/back/Pages/NewsTag/Form.tsx @@ -0,0 +1,103 @@ +// * Packages +import { useForm, usePage } from "@inertiajs/react"; +import { BookTextIcon } from "lucide-react"; +// * Other +import FieldsetWrapper from "@/back/Components/FieldsetWrapper"; +import InputError from "@/back/Components/InputError"; +import SimpleString from "@/back/Components/Inputs/SimpleString"; +import { Methods } from "@/lib/enums"; +import { AppEnv, NewsTagModel } from "@/back/types/global"; +import useTrans from "@/hooks/use-translations"; +import str from "@/hooks/use-string"; +import { useCrudSubmit } from "@/hooks/use-crud-submit"; +import SubmitButton from "@/back/Components/SubmitButton"; +import SimpleColorPicker from "@/back/Components/Inputs/SimpleColorPicker"; +import Slugifycator from "@/back/Components/Inputs/Slugifycator"; + +export default function Form({ + model, + modelName, + modelRoute, + action, + method, +}: { + model?: NewsTagModel; + modelName: string; + modelRoute: string; + action: string; + method: number; +}) { + const { locale } = usePage().props.appEnv as AppEnv; + + /** Form section */ + const { post, setData, data } = useForm({ + _method: method === Methods.POST ? 'post' : 'put', + name: model?.name ? model?.name[locale] : "", + slug: model?.slug ? model?.slug[locale] : "", + color: model?.color ? model?.color : "" + }); + + const submit = useCrudSubmit({ + method, + modelRoute, + modelName, + action, + model, + post + }); + + return ( + + + } + description={useTrans("back.form_subtitle_global")} + > +
+ + + +
+
+
+ +
+ + ); +} diff --git a/resources/ts/back/Pages/NewsTag/Index.tsx b/resources/ts/back/Pages/NewsTag/Index.tsx new file mode 100644 index 00000000..6e12e000 --- /dev/null +++ b/resources/ts/back/Pages/NewsTag/Index.tsx @@ -0,0 +1,182 @@ +// * Packages +import { route } from "ziggy-js"; +import { usePage } from "@inertiajs/react"; +import { AlertCircleIcon, ArchiveIcon, ArrowLeftIcon, Plus } from "lucide-react"; +import { Row } from "@tanstack/react-table"; +// * Components shadcn +import { Badge } from "@/components/ui/badge"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; +// * Other +import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout"; +import DataTable from "@/back/Components/Table/DataTable"; +import DataTableSearch from "@/back/Components/Table/DataTableSearch"; +import DataTableFilterButton from "@/back/Components/Table/DataTableFilterButton"; +import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; +import InputError from "@/back/Components/InputError"; +import { Views } from "@/lib/utils"; +import { useFormatedDate } from "@/hooks/use-formated-value"; +import { + AuthProp, + NewsTagModel, + Resource, +} from "@/back/types/global"; +import str from "@/hooks/use-string"; +import useTrans from "@/hooks/use-translations"; +import { renderTranslationCell } from "@/lib/translationCellFallback"; + +export default function Index({ + newsTagModels, + search, + searchFields, + modelName +}: { + newsTagModels: Resource; + search: string; + searchFields: string; + modelName: string; +}) { + const { auth } = usePage().props as unknown as { + auth: AuthProp; + }; + const { viewAny, viewTrash, create } = auth.policies.newsTags; + const isArchiveRoute = route().current(`back.${modelName}.trash`); + const actionModels = isArchiveRoute ? [ + Views.RESTORATION, + Views.FORCEDELETION, + ] : [ + Views.VISUALIZATION, + Views.EDITION, + Views.DUPLICATION, + Views.ARCHIVATION, + ]; + const columns = [ + { + accessorKey: "name", + header: ({ column }: { column: { id: string } }) => ( + + ), + cell: ({ row }: { row: Row }) => { + return renderTranslationCell( + row.getValue("name") + ) + }, + }, + { + accessorKey: "color", + header: ({ column }: { column: { id: string } }) => ( + + ), + cell: ({ row }: { row: Row }) => { + return ( + + +
+
+ {row.getValue("color")} +
+ ) + }, + }, + { + accessorKey: "news", + header: () => ( +

{str(useTrans(`validation.custom.documentTag.documents`)).ucFirst().value()}

+ ), + cell: ({ row }: { row: Row }) => ( +
+

{row.original.news_count ?? 0}

+
+ ), + }, + { + accessorKey: "updated_at", + header: ({ column }: { column: { id: string } }) => ( + + ), + cell: ({ row }: { row: Row }) => ( + + {useFormatedDate(row.getValue("updated_at"))} + + ), + }, + ]; + const transModel = useTrans(`models.classes.${str(modelName).singular().value()}`, { choice: 2 }); + const transArchiveTitle = useTrans("crud.helpers.archives_model", { params: { model: transModel } }) + const transTitle = str(isArchiveRoute ? transArchiveTitle : transModel).ucFirst().value(); + + const beforeNode = () => { + return isArchiveRoute && viewAny && ( +
+ } + tooltipContent={

{useTrans("back.crud_back_to_list")}

} + /> +
+ ); + }; + const afterNode = () => { + return !isArchiveRoute && ( +
+ {viewTrash && } + tooltipContent={

{useTrans("back.crud_access_trash")}

} + variant="outline" + />} + {create && } + tooltipContent={

{useTrans("back.crud_add_entry")}

} + />} +
+ ); + }; + + return ( + + {isArchiveRoute && ( + <> + + + {useTrans('back.warning')} + +

{useTrans('back.warning_trash')}

+
+
+ + + )} + + +
+ ); +} diff --git a/resources/ts/back/Pages/NewsTag/Show.tsx b/resources/ts/back/Pages/NewsTag/Show.tsx new file mode 100644 index 00000000..2713aac3 --- /dev/null +++ b/resources/ts/back/Pages/NewsTag/Show.tsx @@ -0,0 +1,123 @@ +// * Packages +import { usePage } from "@inertiajs/react"; +import { route } from "ziggy-js"; +// * Components shadcn +import { Badge } from "@/components/ui/badge"; +// * Other +import AuthenticatedLayout from "@/back/Layouts/AuthenticatedLayout"; +import DetailsTable from "@/back/Components/Table/DetailsTable"; +import ModelActions from "@/back/Components/ModelActions"; +import { Views } from "@/lib/utils"; +import { useFormatedDate } from "@/hooks/use-formated-value"; +import { + AppEnv, + AuthProp, + NewsTagModel, + Resource, + SingleResource, + TranslationField, +} from "@/back/types/global"; +import str from "@/hooks/use-string"; +import useTrans from "@/hooks/use-translations"; +import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip"; +import { ArrowLeft } from "lucide-react"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; +import AssociatedNewsList from "@/back/Components/AssociatedNewsList"; +import { renderTranslationCell } from "@/lib/translationCellFallback"; + + +export default function Show({ data, modelName, news }: { data: SingleResource, modelName: string, news: Resource }) { + const { auth, appEnv } = usePage().props as unknown as { + auth: AuthProp; + appEnv: AppEnv; + }; + const { viewAny } = auth.policies.newsTags; + const model = data.data as NewsTagModel; + const actionModels = [ + Views.EDITION, + Views.DELETION, + ]; + const singularModelName = str(modelName).singular().value(); + const transTitle = useTrans("crud.helpers.visualization_model", { + params: { model: useTrans(`models.classes.${singularModelName}`, { choice: 1 }) }, + }); + const columns = [ + { + accessorKey: "name", + header: str(useTrans("validation.attributes.name")).ucFirst().value(), + cell: ({ value }: { value: TranslationField }) => { + return renderTranslationCell( + value + ) + } + }, + { + accessorKey: "slug", + header: str(useTrans("validation.custom.slug")).ucFirst().value(), + cell: ({ value }: { value: TranslationField }) => value[appEnv.locale] + ? value[appEnv.locale] + : (

{useTrans('back.table_not_known')}

), + }, + { + accessorKey: "color", + header: str(useTrans("validation.custom.color")).ucFirst().value(), + cell: ({ value }: { value: string }) => { + return ( + + +
+
+ {value} +
+ ) + } + }, + { + accessorKey: "created_at", + header: str(useTrans("validation.attributes.created_at")).ucFirst().value(), + cell: ({ value }: { value: string }) => { + return ( + {useFormatedDate(value)} + ) + }, + }, + { + accessorKey: "updated_at", + header: str(useTrans("validation.attributes.updated_at")).ucFirst().value(), + cell: ({ value }: { value: string }) => ( + {useFormatedDate(value)} + ), + }, + ]; + + const beforeNode = () => { + return viewAny && ( +
+ } + tooltipContent={

{useTrans("back.crud_back_to_list")}

} + /> +
+ ); + }; + + return ( + + + {/* @ts-expect-error Weird error type on cell. */} + + + + ); +} diff --git a/resources/ts/back/types/global.d.ts b/resources/ts/back/types/global.d.ts index 9a6c351b..7e2e9b92 100644 --- a/resources/ts/back/types/global.d.ts +++ b/resources/ts/back/types/global.d.ts @@ -127,9 +127,21 @@ type NewsModel = { updated_at: Date; deleted_at: Date; categories: NewsCategoryModel[]; + tags: NewsTagModel[]; }; type NewsCategoryModel = { + policies: ModelPolicy; + id: number; + name: TranslationField; + slug: TranslationField; + news_count: number; + created_at: Date; + updated_at: Date; + deleted_at: Date; +} + +type NewsTagModel = { policies: ModelPolicy; id: number; name: TranslationField; @@ -152,7 +164,7 @@ type CompanyModel = { latitude: number; longitude: number; activity_id: number; - sector_id: number|null; + sector_id: number | null; published: boolean; created_at: Date; updated_at: Date; @@ -231,7 +243,8 @@ type Model = | CompanySectorModel | DocumentTagModel | ActivityLogModel - | NewsCategoryModel; + | NewsCategoryModel + | NewsTagModel; // Common policy type. type CommonPolicy = { diff --git a/resources/views/components/front/sections/news.blade.php b/resources/views/components/front/sections/news.blade.php index 5790d180..8875db3b 100644 --- a/resources/views/components/front/sections/news.blade.php +++ b/resources/views/components/front/sections/news.blade.php @@ -13,15 +13,15 @@
- @if (isset($news->category_labels)) + @if (isset($news->tag_labels))
-
- {{ $news->category_labels }} +
+ {{ $news->tag_labels }}
@endif
{{ $news['title'] }}
-
+
{{ $news->publishedAtFormatted() }}
diff --git a/resources/views/front/pages/news/show.blade.php b/resources/views/front/pages/news/show.blade.php index be9835c5..2aa1af00 100644 --- a/resources/views/front/pages/news/show.blade.php +++ b/resources/views/front/pages/news/show.blade.php @@ -8,17 +8,17 @@
@include('front.breadcrumbs.breadcrumb-body')
- @if (isset($model['category_labels'])) + @if (isset($model['tag_labels']))
-
- {{ $model['category_labels'] }}
+ {{ $model['tag_labels'] }}
@endif

{{ $model['title'] }}

-
{{ $model->publishedAtFormatted() }}
diff --git a/routes/web-back.php b/routes/web-back.php index 83cb3223..428035c2 100644 --- a/routes/web-back.php +++ b/routes/web-back.php @@ -12,6 +12,7 @@ use App\Http\Controllers\Back\DynamicPageController; use App\Http\Controllers\Back\InputsController; use App\Http\Controllers\Back\NewsCategoryController; use App\Http\Controllers\Back\NewsController; +use App\Http\Controllers\Back\NewsTagController; use App\Http\Controllers\Back\PageConfigController; use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; @@ -84,6 +85,7 @@ Route::prefix('admin') Route::delete('/news/{news}/force', [NewsController::class, 'forceDestroy']) ->name('news.forceDestroy'); Route::resource('news', NewsController::class); + Route::get('/news/{news}/duplicate', [NewsController::class, 'duplicate']) ->name('news.duplicate'); @@ -98,6 +100,17 @@ Route::prefix('admin') Route::get('/news-categories/{news_category}/duplicate', [NewsCategoryController::class, 'duplicate']) ->name('news-categories.duplicate'); + // * NEWS TAGS. + Route::get('/news-tags/trash', [NewsTagController::class, 'index']) + ->name('news-tags.trash'); + Route::patch('/news-tags/{news_tag}/restore', [NewsTagController::class, 'restore']) + ->name('news-tags.restore'); + Route::delete('/news-tags/{news_tag}/force', [NewsTagController::class, 'forceDestroy']) + ->name('news-tags.forceDestroy'); + Route::resource('news-tags', NewsTagController::class); + Route::get('/news-tags/{news_tag}/duplicate', [NewsTagController::class, 'duplicate']) + ->name('news-tags.duplicate'); + // * COMPANIES. Route::get('/companies/trash', [CompanyController::class, 'index']) ->name('companies.trash');