Download the PHP package antoninmasek/laravel-route-directory-macro without Composer

On this page you can find all versions of the php package antoninmasek/laravel-route-directory-macro. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-route-directory-macro

Easily load all defined routes from a directory with multiple route files.

Latest Version on Packagist Total Downloads

This package registers loadFromDirectory macro on the Route facade. Using this macro you can easily load all defined routes from multiple files within a directory.

Installation

You can install the package via composer:

Motivation behind the macro

While it is perfectly all right to have all routes inside a single file, I found myself reaching for multiple files quite often. For some reason I just prefer the fact, that I have a single file per entity or domain. And to make the route registration process easier for myself I wrote a simple piece of code which I was copying from project to project. So I decided to package it up, so I don't have to do it anymore.

Basic usage

Consider the following routes directory structure:

Now, traditionally we would have to require each file from our web.php or any other entry point for our routes. The other option is to register each file in the bootstrap/app.php (or RouteServiceProvider for Laravel 10 and below).

Using this package we can just do the following:

This will register routes from all files inside these two directories. While the first call registers routes from routes/app directory and assigns web and auth auth middleware, the second call registers routes from routes/public directory and only assigns web middleware.

Laravel 11.x or later

Use it inside bootstrap/app.php

Laravel 10.x and below

Use it inside RouteServiceProvider.php

Parameters

Path

The only required parameter is the path to the directory with your route files. The macro uses base_path helper in the background, the path is relative to the base path of your project.

If you wish to use an absolute path, you have to have / at the start of your path string. Then the base_path helper won't be used.

Middleware

This is an array, where you can specify which middleware should be applied to routes in the specified directory.

Prefix

If you specify a prefix, then all routes in the directory will be prefixed. Let's look at the following example:

Then all routes would have admin/ prefix

Name

By default, when you specify a prefix the name will automatically become the prefix with . at the end. So for prefix admin the name would be admin..

If you wish to use your name, just pass it as the fourth argument. Or if you wish to just use prefix without any name set the name argument to false.

Hidden files

By default, the macro excludes files starting with . to prevent hidden files from being loaded. You can also use this to your advantage in a scenario, where you have routes file, which you don't want to load yet. You can just prefix it with a dot and that's it. For example routes/.secret.php.

Loading hidden files in specific environments

To take even greater advantage of hidden files, you can specify environments in which you would like them to be loaded. This is very useful, when you want to work on new routes in your local environment, but not yet in production.

To do this you should publish the config file and specify the desired environments in the register_hidden_routes_in_environments config array.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-route-directory-macro with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
spatie/laravel-package-tools Version ^1.16
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package antoninmasek/laravel-route-directory-macro contains the following files

Loading the files please wait ....