承接 g4t/easyroute 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

g4t/easyroute

最新稳定版本:0.0.2

Composer 安装命令:

composer require g4t/easyroute

包简介

Modern Laravel 13 routing using PHP 8 attributes with auto-generation, nested controller support, and native route caching.

README 文档

README

EasyRoute Logo

🌟 Laravel 13 G4T easyRoute Attributes

A Laravel 13 package that lets you define routes using PHP 8 attributes with full support for Controller-level routes, Method-level routes, middleware, subfolders, and caching via Laravel’s routes-v7.php.

EasyRoute Features Banner

🚀 Features

  • Controller-level route attributes (#[Route(uri: 'users')])
  • Method-level route attributes (#[Get], #[Post], #[Put], #[Patch], #[Delete], #[Any])
  • Auto route generation using method names or onController option
  • Middleware support (controller-level + method-level)
  • Nested folder support for controllers
  • Route caching using Laravel compiled routes (bootstrap/cache/routes-v7.php)
  • Configurable Controllers paths

⚙️ Installation

Install via Composer:

composer require g4t/easyroute

Publish config:

php artisan vendor:publish --provider "G4T\EaseRoute\EaseRouteServiceProvider"

This creates config/route-attribute.php:

return [
    'controllers_path' => [app_path('Http/Controllers')],
    'cache' => true,
];

📝 Usage Controller-level Route

<?php

namespace App\Http\Controllers;

use G4T\EaseRoute\Attributes\Route;
use G4T\EaseRoute\Attributes\Get;
use G4T\EaseRoute\Attributes\Post;

#[Route(uri: 'users', middleware: ['auth'])]
class UserController extends Controller
{
    #[Get]
    public function index()
    {
        return "List of users";
    }

    #[Get(onController: true)]
    public function show($id)
    {
        return "User: $id";
    }

    #[Post('create')]
    public function store()
    {
        return "Create user";
    }
}

Supported HTTP Methods

Attribute HTTP Method
#[Get] GET
#[Post] POST
#[Put] PUT
#[Patch] PATCH
#[Delete] DELETE
#[Any] Any method

⚡ Route Caching

To improve performance, EasyRoute can use Laravel compiled routes instead of scanning controllers for every request.

Workflow Diagram

Steps:

  1. Ensure cache is enabled in config/route-attribute.php:
'cache' => true
  1. Run the caching command:
php artisan route:cache

⚙️ Configuration

return [
    'controllers_path' => [app_path('Http/Controllers')],
    'cache' => true,
];
  • controllers_path → Array of paths where your controllers reside
  • cache → Use cached routes from routes-v7.php

📝 Notes Supports nested folders in controllers_path.

Use onController: true to auto-generate URI based on Controller and Method names.

Middleware is merged: controller-level + method-level.

Fully compatible with Laravel 13 attributes syntax.

GET      users                          UserController@index
GET      user/show/{id}                 UserController@show
POST     users/create                    UserController@store
app/
├─ Http/
│  ├─ Controllers/
│  │  ├─ UserController.php
│  │  └─ Admin/
│  │     └─ AdminController.php
bootstrap/
└─ cache/
   └─ routes-v7.php
config/
└─ route-attribute.php

✅ Notes for Developers

  • Place your controllers inside controllers_path
  • Add #[Route(...)] at the class level
  • Add #[Get], #[Post], etc. at method level
  • Use onController: true for automatic route naming Run php artisan route:cache to generate cached routes

EasyRoute makes your Laravel 13 routing modern, clean, and high-performance.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固