Skip to content

Commit

Permalink
Feat: Simplify route loading from the routes/* folders.
Browse files Browse the repository at this point in the history
  • Loading branch information
3m1n3nc3 committed Sep 13, 2024
1 parent 51c63c6 commit 9a6a730
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Route;

if (file_exists(base_path('routes/api'))) {
array_filter(File::files(base_path('routes/api')), function (\Symfony\Component\Finder\SplFileInfo $file) {
if ($file->getExtension() === 'php') {
Route::middleware('api')->group($file->getPathName());
}
});
}

Route::get('/', function (Request $request) {
return [
'api' => config('app.name'),
Expand All @@ -25,3 +16,8 @@
Route::get('/admin', function (Request $request) {
return $request->user();
})->middleware('auth:sanctum');

$files = glob(__DIR__ . '/api/*.php');
foreach ($files as $file) {
Route::middleware('api')->group($file);
}

0 comments on commit 9a6a730

Please sign in to comment.