引入依赖包
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,阅读量:1530