# Routes

Routes map URLs to controller actions. Every page in your package โ€” the index list, the edit form, the delete handler โ€” needs a route entry, and Krayin discovers them by loading a routes file from your package's service provider.

This page picks up where Getting Started left off โ€” you already have a packages/Webkul/Example/src/ skeleton and a registered service provider. For background on Laravel routing, see the Laravel routing docs (opens new window).

# ๐Ÿ“ Create the routes file

# 1. Add a Routes/ folder

Inside packages/Webkul/Example/src/, create a Routes/ folder and a routes.php file:

packages
โ””โ”€โ”€ Webkul
    โ””โ”€โ”€ Example
        โ””โ”€โ”€ src
            โ”œโ”€โ”€ ...
            โ””โ”€โ”€ Routes
                โ””โ”€โ”€ routes.php

# 2. Define your first route

Paste this into routes.php:

<?php

use Illuminate\Support\Facades\Route;
use Webkul\Example\Http\Controllers\Admin\ExampleController;

Route::group([
    'middleware' => ['web', 'admin_locale'],
    'prefix' => config('app.admin_path'),
], function () {
    Route::get('/examples', [ExampleController::class, 'index'])
        ->name('admin.examples.index');
});

The group prefixes every route with the admin URL (config('app.admin_path')) and applies the web and admin_locale middleware. Adjust the middleware list to match your route's needs โ€” if it needs admin auth, add 'admin'; if it should be public, drop admin_locale.

Always name your routes

Naming the route (->name('admin.examples.index')) lets you reference it later with route('admin.examples.index') from controllers, views, and the Admin Menu config โ€” without hard-coding the URL.

# โš™๏ธ Wire the routes into the service provider

Open packages/Webkul/Example/src/Providers/ExampleServiceProvider.php and call loadRoutesFrom() inside boot():

<?php

namespace Webkul\Example\Providers;

use Illuminate\Support\ServiceProvider;

class ExampleServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $this->loadRoutesFrom(__DIR__ . '/../Routes/routes.php');
    }

    public function register(): void
    {
        //
    }
}

loadRoutesFrom() is what tells Laravel to include your package's routes during the framework's route-registration phase. Without it, your routes silently never load.

# ๐Ÿ”Œ HTTP method reference

A single Krayin resource typically needs five routes โ€” one per HTTP verb. Here's the full set for the Example example:

Route::get('examples',           [ExampleController::class, 'index'])->name('admin.examples.index');
Route::post('examples',          [ExampleController::class, 'store'])->name('admin.examples.store');
Route::put('examples/{id}',      [ExampleController::class, 'update'])->name('admin.examples.update');
Route::patch('examples/{id}',    [ExampleController::class, 'partialUpdate'])->name('admin.examples.partial-update');
Route::delete('examples/{id}',   [ExampleController::class, 'destroy'])->name('admin.examples.destroy');
Method When to use it
GET Fetch / display a resource (list page, detail page, edit form)
POST Create a new resource (form submit on create)
PUT Replace an existing resource entirely (full update)
PATCH Update one or two fields on an existing resource (partial update)
DELETE Remove a resource

# ๐Ÿงช Verify

Confirm your routes are registered:

php artisan route:list --path=examples

You should see your route listed with its URL, method, name, and the controller action it maps to. If nothing appears, run composer dump-autoload and re-check that loadRoutesFrom() is inside boot() (not register()).

# ๐Ÿ“ Next steps

  • Migrations โ€” create the examples table the routes will read and write.
  • Controllers โ€” build the ExampleController that each route points at.
  • Access Control List โ€” gate admin routes by user permission.
  • Admin Menu โ€” surface your admin.examples.index route in the sidebar.