Skip to content

Commit

Permalink
routes file
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Jun 8, 2023
1 parent fd39df8 commit 0367f57
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 61 deletions.
4 changes: 2 additions & 2 deletions src/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function boot(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/news.php', 'typicms.modules.news');

$this->loadRoutesFrom(__DIR__ . '/../routes/news.php');

$this->loadViewsFrom(__DIR__ . '/../../resources/views/', 'news');

$this->publishes([__DIR__ . '/../../database/migrations/create_news_table.php.stub' => getMigrationFileName('create_news_table')], 'typicms-migrations');
Expand All @@ -42,8 +44,6 @@ public function register(): void
{
$this->app['config']->push('typicms.feeds', ['module' => 'news']);

$this->app->register(RouteServiceProvider::class);

$this->app->bind('News', News::class);
}
}
59 changes: 0 additions & 59 deletions src/Providers/RouteServiceProvider.php

This file was deleted.

50 changes: 50 additions & 0 deletions src/routes/news.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use TypiCMS\Modules\Core\Facades\TypiCMS;
use TypiCMS\Modules\Core\Http\Controllers\FeedController;
use TypiCMS\Modules\News\Http\Controllers\AdminController;
use TypiCMS\Modules\News\Http\Controllers\ApiController;
use TypiCMS\Modules\News\Http\Controllers\PublicController;

/*
* Front office routes
*/
if ($page = TypiCMS::getPageLinkedToModule('news')) {
$middleware = $page->private ? ['public', 'auth'] : ['public'];
foreach (locales() as $lang) {
if ($page->isPublished($lang) && $uri = $page->uri($lang)) {
Route::middleware($middleware)->prefix($uri)->name($lang . '::')->group(function (Router $router) {
$router->get('/', [PublicController::class, 'index'])->name('index-news');
$router->get('{module}-feed.xml', FeedController::class)->name('news-feed');
$router->get('{slug}', [PublicController::class, 'show'])->name('news');
});
}
}
}

/*
* Admin routes
*/
Route::middleware('admin')->prefix('admin')->name('admin::')->group(function (Router $router) {
$router->get('news', [AdminController::class, 'index'])->name('index-news')->middleware('can:read news');
$router->get('news/export', [AdminController::class, 'export'])->name('export-news')->middleware('can:read news');
$router->get('news/create', [AdminController::class, 'create'])->name('create-news')->middleware('can:create news');
$router->get('news/{news}/edit', [AdminController::class, 'edit'])->name('edit-news')->middleware('can:read news');
$router->post('news', [AdminController::class, 'store'])->name('store-news')->middleware('can:create news');
$router->put('news/{news}', [AdminController::class, 'update'])->name('update-news')->middleware('can:update news');
});

/*
* API routes
*/
Route::middleware(['api', 'auth:api'])->prefix('api')->group(function (Router $router) {
$router->get('news', [ApiController::class, 'index'])->middleware('can:read news');
$router->patch('news/{news}', [ApiController::class, 'updatePartial'])->middleware('can:update news');
$router->delete('news/{news}', [ApiController::class, 'destroy'])->middleware('can:delete news');

$router->get('news/{news}/files', [ApiController::class, 'files'])->middleware('can:update news');
$router->post('news/{news}/files', [ApiController::class, 'attachFiles'])->middleware('can:update news');
$router->delete('news/{news}/files/{file}', [ApiController::class, 'detachFile'])->middleware('can:update news');
});

0 comments on commit 0367f57

Please sign in to comment.