lizzyman04/file-router-laravel

Laravel adapter for lizzyman04/file-router — Next.js-style file-based routing inside Laravel.

Maintainers

Package info

github.com/lizzyman04/file-router-laravel

pkg:composer/lizzyman04/file-router-laravel

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-18 16:58 UTC

This package is auto-updated.

Last update: 2026-06-18 17:04:57 UTC


README

Laravel adapter for lizzyman04/file-router — Next.js-style file-based routing inside a Laravel app. The directory structure becomes the route table; routes are registered as native Laravel routes, so they coexist with routes/web.php / routes/api.php and inherit Laravel's middleware, container, and route caching.

Dispatch is fully deferred to Laravel's router — this package only resolves which file handles a URL.

Requirements

  • PHP 8.2+
  • Laravel 11 or 12

Install

composer require lizzyman04/file-router-laravel

Until the core lizzyman04/file-router is published on Packagist, add its repository to your app's composer.json:

"repositories": [
    { "type": "vcs", "url": "https://github.com/lizzyman04/file-router" }
]

Publish the config:

php artisan vendor:publish --tag=file-router-config
// config/file-router.php
return [
    'routes_path' => base_path('routes/pages'), // directory scanned for routes
    'prefix'      => '',                         // e.g. 'api' to serve under /api/*
    'middleware'  => ['web'],                    // middleware applied to all routes
    'cache_dir'   => null,                       // e.g. storage_path('framework/cache/file-router')
];

The service provider is auto-discovered.

Route files

Each route file returns a callable and declares its HTTP methods with a // @methods header (defaults to GET):

// routes/pages/users/[id].php
<?php
// @methods GET, PUT

use Illuminate\Http\Request;

return function (Request $request, array $params) {
    return response()->json([
        'id'     => $params['id'],
        'method' => $request->method(),
    ]);
};

Whatever the callable returns is handed to Laravel, which turns it into a response (arrays → JSON, strings → HTML, Response/Responsable pass through).

Filesystem → URL

File on disk URL Notes
index.php /
about.php /about
users/[id].php /users/{id} $params['id']
posts/[id]/comments.php /posts/{id}/comments
files/[...path].php /files/{path} (catch-all, .*) $params['path'] is the rest of the URL
(admin)/dashboard.php /dashboard group folder stripped

Matching is specificity-ordered: static > dynamic > catch-all.

Middleware & coexistence

  • Middleware from the config is applied to every file-based route (they run through Laravel's normal pipeline).
  • File-based routes are added to Laravel's route collection on boot, so they live alongside your routes/web.php and routes/api.php routes.
  • Unmatched methods/paths produce Laravel's own 405/404 responses.

Testing

composer test

Tests run against a real Laravel app via orchestra/testbench.

License

MIT