尼好再见

4775 经验值

很喜欢你讲视频的风格!简洁明了,有空的时候还是希望可以录制一些放上来!从第一次接触 laravel 到现在能用 laravel 开发真的对我帮助非常大!可能你不记得我,但是我一直有在关注你,关注这个网站,以后也会经常过来看看的!

出去干嘛啦?老实交代!?

我在使用 Laravel Passport 进行用户登录认证的时候如果 access_token 过期就会返回 "message": "Unauthenticated." 这时候会写入报错的日志,怎么去掉这个报错的日志啊?

[2017-12-27 10:58:54] local.ERROR: The resource owner or authorization server denied the request. {"exception":"[object] (League\\OAuth2\\Server\\Exception\\OAuthServerException(code: 9): The resource owner or authorization server denied the request. at /Users/system/Workspace/stock-spa/vendor/league/oauth2-server/src/Exception/OAuthServerException.php:168)
[stacktrace]
#0 /Users/system/Workspace/stock-spa/vendor/league/oauth2-server/src/AuthorizationValidators/BearerTokenValidator.php(82): League\\OAuth2\\Server\\Exception\\OAuthServerException::accessDenied('Access token ha...')
#1 /Users/system/Workspace/stock-spa/vendor/league/oauth2-server/src/ResourceServer.php(82): League\\OAuth2\\Server\\AuthorizationValidators\\BearerTokenValidator->validateAuthorization(Object(Zend\\Diactoros\\ServerRequest))
#2 /Users/system/Workspace/stock-spa/vendor/laravel/passport/src/Guards/TokenGuard.php(110): League\\OAuth2\\Server\\ResourceServer->validateAuthenticatedRequest(Object(Zend\\Diactoros\\ServerRequest))
#3 /Users/system/Workspace/stock-spa/vendor/laravel/passport/src/Guards/TokenGuard.php(90): Laravel\\Passport\\Guards\\TokenGuard->authenticateViaBearerToken(Object(Illuminate\\Http\\Request))
#4 /Users/system/Workspace/stock-spa/vendor/laravel/passport/src/PassportServiceProvider.php(267): Laravel\\Passport\\Guards\\TokenGuard->user(Object(Illuminate\\Http\\Request))
#5 [internal function]: Laravel\\Passport\\PassportServiceProvider->Laravel\\Passport\\{closure}(Object(Illuminate\\Http\\Request), NULL)
#6 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Auth/RequestGuard.php(58): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request), NULL)
#7 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Auth/GuardHelpers.php(50): Illuminate\\Auth\\RequestGuard->user()
#8 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(61): Illuminate\\Auth\\RequestGuard->check()
#9 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(41): Illuminate\\Auth\\Middleware\\Authenticate->authenticate(Array)
#10 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Auth\\Middleware\\Authenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure), 'api')
#11 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#12 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#13 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle(Object(Illuminate\\Http\\Request), Object(Closure), 500, '1')
#14 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#15 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#16 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Router.php(660): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#17 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#18 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Router.php(601): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#19 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Router.php(590): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#20 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#21 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#22 /Users/system/Workspace/stock-spa/vendor/fideloper/proxy/src/TrustProxies.php(56): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#23 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#24 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#25 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#26 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#27 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#28 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#29 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#30 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#31 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#32 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#33 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#34 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#35 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#36 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#37 /Users/system/Workspace/stock-spa/vendor/barryvdh/laravel-cors/src/HandlePreflight.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#38 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Barryvdh\\Cors\\HandlePreflight->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#39 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#40 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#41 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#42 /Users/system/Workspace/stock-spa/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#43 /Users/system/Workspace/stock-spa/public/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#44 /Users/system/.composer/vendor/laravel/valet/server.php(133): require('/Users/jinjiale...')
#45 {main}
"}
"laravel.log" 49L, 9409C

Jelly 我觉的这个 Laravel 5.5 Api Resource 确实可以再讲的深入点!

Resource 里有个with 我想有没有办法把数据传递个 with 这样就可以 附加其他额外信息了!

我还有个问题,现在是用 Eloquent ORM 查询出的数据可以生成 API,但是在现实生产环境中往往会出现不同的情况,比如对查询的数据需要重构,可能需要加入一些额外字段,比如我返回User表信息的同时,我需要从我的配置表中查询出某两个字段的值一起返回,但是配置表和User表没有直接关系,还有我有时候需要从 redis 里获取数据,增加到某个查询的结果中,这种情况下我对数组的重构是在 Resource 中进行还是在外面!

一脸懵逼!这个写了可以不用写路由直接用吗?正常的 Resource 像官方文档里那样不是需要 new User($users); 这个样子吗?

这个和直接 return 没什么区别啊!问题还是存在的,还是需要创建多个 resourece