# Routes
# Naming
All public-facing urls must use kebab-case.
// Bad
example.com/openPositions
// Good
example.com/open-positions
A route url should not start with / unless the url would be an empty string.
// Bad
Route::get('', HomeController::class);
Route::get('/open-positions', [OpenPositionsController::class, 'index']);
// Good
Route::get('/', HomeController::class, 'index');
Route::get('open-positions', [OpenPositionsController::class, 'index']);
# Route actions
Always use the route tuple notation.
// Bad
Route::get('open-positions', 'OpenPositionsController@index');
// Good
Route::get('open-positions', [OpenPositionsController::class, 'index']);
Single action, invokable controllers should always be specified directly, without array syntax.
// Bad
Route::get('user-cleanup', [UserCleanupController::class, '__invoke']);
// Good
Route::get('user-cleanup', UserCleanupController::class);
Route controllers should always use fully-classified class names. Avoid using route namespaces.
// Bad
Route::get('open-positions', 'UserCleanupController');
// Good
use App\Http\Controllers\UserCleanupController;
Route::get('open-positions', UserCleanupController::class);
# HTTP verbs
All routes have an http verb, that's why we like to put the verb first when defining a route. It makes a group of routes very readable. Any other route options should come after it.
// Bad
Route::name('home')->get('/', HomeController::class);
Route::name('openPositions')->get([OpenPositionsController::class, 'index']);
// Good
Route::get('/', HomeController::class)->name('home');
Route::get('open-positions', [OpenPositionsController::class, 'index'])->name('openPositions');
# Prefixing
In a single route file use route prefixing only for a small number of routes. When prefix covers 20+ routes it becomes hard to read and follow.
If you need to prefix large number of routes, this is a good indicator that you need a dedicated route file for those routes and with route prefix defined directly on RouteServiceProvider.
# Parameters
Route parameters must use camelCase.
// Bad
Route::get('news/{news-item}', [NewsController::class, 'show']);
// Good
Route::get('news/{newsItem}', [NewsController::class, 'show']);
# Names
Route names must be written as plural and use camelCase.
// Bad
Route::get('open-positions', [OpenPositionsController::class, 'index'])->name('open-positions');
// Good
Route::get('open-positions', [OpenPositionsController::class, 'index'])->name('openPositions');
Route names should follow the uri path segments.
// Bad
Route::get('jobs/open-positions', [OpenPositionsController::class, 'index'])->name('openPositions');
// Good
Route::get('jobs/open-positions', [OpenPositionsController::class, 'index'])->name('jobs.openPositions');
# Resource routes
All resource routes must be in plural form.
// Bad
Route::get('user/{user}', [UserController::class, 'show']);
// Good
Route::get('users/{user}', [UserController::class, 'show']);
# Route-model binding
Use route-model binding whenever possible.
// Bad
Route::get('users/{id}', [UserController::class, 'show']);
// Good
Route::get('users/{user}', [UserController::class, 'show']);
← Controllers Models →