xiashaung / inject
laravel attribute inject
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/xiashaung/inject
Requires
- php: >=8.1
This package is auto-updated.
Last update: 2025-09-21 10:18:24 UTC
README
1. 自动为路由组 web,api提供注入服务
其他文档
使用示例
namespace App\Http\Controllers; use Xiashaung\Inject\Attribute\Inject; use App\Services\OrderService; use Illuminate\Http\Request; class TestController extends Controller { #[Inject] //使用inject标注需要注入服务,OrderService 自动使用服务容器解析实例,如果 OrderService 里有静态方法 make ,自动调用 protected OrderService $orderService;
其他方法使用
//解析给定的类并为属性自动注入,返回实例 inject($classname,$args)->method()
其他路由组
在AppServiceProvider的boot方法中添加
Route::pushMiddlewareToGroup('group_name', Xiashaung\Inject\Middleware\ControllerInject::class);