函数注入


引入依赖包

composer require spatie/macroable

 

实例

 

   // 用户ID
        Request::macro('userId', function ($isVerify = false) use ($userId) {
            if ($isVerify && !$userId) {
                throw new AuthException('请登录。');
            }

            return $userId;
        });

 


use Spatie\Macroable\Macroable;

/**
 * @method userId($isVerify = true)
 */
class Request extends \think\Request
{
    use Macroable;

}

 

$userId = request()->userId(false);

 

 

发布时间 : 2023-02-28,阅读量:1081
本文链接:https://upwqy.com/details/33.html
ThinkPHP6和Workerman结合实例 签名生成校验