amir-hossein5/laravel-routin

筛选 Laravel 应用程序的路由

v1.2.0 2022-03-14 15:38 UTC

This package is auto-updated.

Last update: 2024-09-23 18:43:15 UTC


README

⚠️ 此软件包仅查找具有名称的路由。

此软件包提供 Laravel 应用程序路由之间的搜索。
例如,当用户准备创建一个菜单项并需要将其链接到页面时,可以直接显示并选择预期的路由,而不是手动编写。

Routin::routes()
  ->withoutParameter()
  ->method('get')
  ->getUri();

输出将是那些没有 任何参数 且动词为 GETuri 路由。

array:3 [▼
  0 => "/"
  1 => "user"
  2 => "user/create"
]

先决条件

  • Laravel ^8.0|^9.0
  • PHP 8

安装

composer require amir-hossein5/laravel-routin

用法

筛选

注意:方法没有顺序,但您必须从 ::routes() 开始使用。

获取器

过滤路由后,您需要通过以下方法获取它们

手动获取路由

use AmirHossein5\Routin\Facades\Routin;


Routin::routes()
  ->withoutParameter()
  ->get(fn ($route) => [
    $route->uri => $route
  ])
  
// output

array:2 [▼
  "user/create" => Illuminate\Routing\Route {#1109 ▶}
  "book/{book}" => Illuminate\Routing\Route {#1108 ▶}
  ...
]

请参阅 https://laravel.net.cn/api/8.x/Illuminate/Routing/Route.html 中的可用方法

get()

use AmirHossein5\Routin\Facades\Routin;


Routin::routes()
  ->withoutParameter()
  ->method('post')
  ->get()
  
// output

array:2 [▼
  "user.store" => Illuminate\Routing\Route {#1109 ▶}
  "book.store" => Illuminate\Routing\Route {#1108 ▶}
]

返回一个包含 名称键Laravel 的 Illuminate\Routing\Route 对象值数组

getUri()

Routin::routes()
  ->withoutParameter()
  ->method('get')
  ->getUri()

// output

array:3 [▼
  0 => "/"
  1 => "user"
  2 => "user/create"
]

返回一个包含 路由 uri 值数组

getParameters()

Routin::routes()
  ->method('put')
  ->getParameters()

// output

array:2 [▼
  "user.update" => array:1 [▼
    0 => "user"
  ]
  "book.update" => array:1 [▼
    0 => "book"
  ]
]

返回一个包含 名称键 和值的 数组,以及参数的 数组

getName()

Routin::routes()
  ->getName()

// output

array:7 [▼
  0 => "user.index"
  1 => "user.create"
  2 => "user.store"
  3 => "user.show"
  4 => "user.edit"
  5 => "user.update"
  6 => "user.destroy"
]

返回一个包含 路由名称值数组

许可证

许可证