Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing 400+ routes in Laravel with PhpStorm autocompletion [closed]

I'm wondering how to deal with 400+ Routes.

We currently separate all the routes into multiple files according to the controller namespace they belong to.

The structure of App/Http/Routes looks something like this:

- Auth.php
- Marketing.php
- Orders.php

All our routes are named. But here comes the actual problem we are having.

Our routes are named by using Classes filled with Constants that define the route name.

namespace App\Http\Controllers\Marketing;

class RouteConstants
{
    /**
     * MarketingController
     */
    const INDEX = 'marketing.index';
    const DISABLED = 'marketing.disabled';

These Constant Classes are located in the Controller namespace. They are then used in the Marketing.php routes file like so:

/**
 * Marketing Routes
 */
Route::group(['namespace' => 'App\Http\Controllers\Marketing'], function() {

    /**
     * MarketingController Routes
     */
    Route::get('marketing/overview', [
        'uses' => 'MarketingController@index',
        'as' => MarketingRoutes::INDEX
    ]);

    Route::get('marketing/disabled', [
        'uses' => 'MarketingController@showDisabled',
        'as' => MarketingRoutes::DISABLED
    ]);```

This is done because it allows us to use the PhpStorm autocomplete features and also see where each route is used.

But the problem with this is that we are using two systems at the same time. Laravel's internal routing naming system and at the same time we are using our own system defining the names as constants.

There must be a better way to manage this amount of routes and having a way to check for usages in the project files.

Currently it is also pretty messy in our views:

<a href="{{ route(App\Http\Controllers\Marketing\RouteConstants::INDEX) }}">Marketing</a>

I already tried the Laravel plugin for PhpStorm but this doesn't work properly when having a folder with routes that are automatically loaded into the RouteServiceProvider.

like image 379
Koen van den Heuvel Avatar asked Oct 29 '22 14:10

Koen van den Heuvel


1 Answers

Noted in the changelog of the Laravel Plugin for PhpStorm (version 0.11), support was added for Laravel 5.3's routes structure.

I suggest you move the routes directory to the root directory of your project. Just like Laravel 5.3 has. For example: app/Http/Routes/ becomes routes/.

When useing version 0.11 of the plugin and you have the 5.3 folder structure I see no reason auto suggest for the route names wouldn't work.

Hope this helps!

like image 135
Robin Valk Avatar answered Nov 01 '22 03:11

Robin Valk