Skip to content

Getting Started

macropay-solutions edited this page Jun 4, 2025 · 8 revisions

1. Start a new project with Maravel

2. Optimize your new project with Maravel

3. Restrict routes by domain with Maravel

1. Start a new project with Maravel

Run in terminal:

composer create-project macropay-solutions/maravel your-project-name

or download the zip project, extract it and rename its folder.

Run in terminal:

composer install

Start building your project.

Optionally we recommend you to use our AUTO cruFd libs suite by running in terminal:

composer require --dev macropay-solutions/laravel-crud-wizard-generator

The generator will help you generate the cruFd classes required for exposing an already existing table via API.

composer require macropay-solutions/laravel-crud-wizard-decorator-free

The decorator will require also macropay-solutions/laravel-crud-wizard-free which contains important retroactive bug fixes and useful new features. See their documentation for more info on how to use them.

2. Optimize your new project with Maravel

On each deploy cache your routes and configs in php files by running:

php artisan route:cache
php artisan config:cache

These will create cached php files in bootstrap/cache folder.

Note that nikic/fast-route package will also create its cache route php file on first access of a dynamic route.

3. Restrict routes by domain with Maravel

Create a new middleware:

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class DomainMiddleware
{
    public function handle(Request $request, Closure $next, string $urlEncodedCsvUrls): mixed
    {
        if (\str_contains(\urldecode($urlEncodedCsvUrls), $_SERVER['HTTP_HOST'] ?? '*')) {
            return $next($request);
        }

        return \response(status: 404);
    }
}

Add in bootstrap/app.php:

$app->routeMiddleware([
     'url.encoded.domains' => \App\Http\Middleware\DomainMiddleware::class,
]);

Add in routes/web.php:

$router->group(
    [
        'middleware' => [
            'url.encoded.domains:' . \urlencode(\rtrim(\env('APP_URL2'), ',') . ',' . \env('APP_URL'))
    ],
    function (Router $router): void {
        $router->post('/login', 'Auth\AuthController@login');
    }
);

Note that the routes MUST NOT OVERLAP from one domain group to another so, make sure each group of domains uses its own prefix.