版权声明:本文为ywcmoon原创文章,未经允许不得转载。 https://blog.csdn.net/qq_39251267/article/details/82626928
使用Request
对象的hook
方法的注入功能,在Request
请求对象中添加自定义方法
// 通过hook方法注入动态方法
Request::hook('user','getUserInfo');
getUserInfo
函数定义如下
function getUserInfo(Request $request, $userId)
{
// 根据$userId获取用户信息
return $info;
}
在控制器中调用
public function index()
{
$info = Request::instance()->user($userId);
}