在模型级别获取`Authorizer :: getResourceOwnerId()`

时间:2018-11-04 03:44:45

标签: laravel-5 oauth oauth-2.0

我正在使用Lucasdegasperi的OAuth2作为Laravel 5.1。在提出任何其他请求之前,我先通过服务器请求访问令牌并登录用户。

然后,使用此access_token,我得到List<DateModel> dateList = Arrays.asList( new DateModel(18,"1"), //DateModel(int date, String value) new DateModel(18,"2"), new DateModel(18,"3"), new DateModel(19,"1"), new DateModel(19,"2"), new DateModel(19,"3"), new DateModel(19,"4") ); Observable.fromIterable(dateList) .groupBy(r -> r.getDate()) .flatMapSingle(Observable::toList) //.flatMapSingle(g -> g.toList()) .subscribe(group -> System.out.println("dateList size: "+group.size())); System.out: dateList size: 3 dateList size: 4

如果我尝试访问控制器中的model1,则可以毫无问题。但是,如果我尝试访问预先加载的模型定义中的Authorizer::getResourceOwnerId(),则会因错误而中断:

  

试图在没有活动访问令牌laravel的情况下访问会话数据

问题:如何在模型级别获得Authorizer::getResourceOwnerId()

路线:

Authorizer::getResourceOwnerId()

Model1Controller:

$router->get('model1s/{model1}', 'Resources\Model1Controller@show');

模型1:

use LucaDegasperi\OAuth2Server\Facades\Authorizer;
use App\User;
class Model1Controller extends Controller
{
    ...
    public function show(Model $model)
    {
        $owner_id = Authorizer::getResourceOwnerId(); // no error

        die($owner_id); // has no issue getting owner ID

        return $model;
    }

模型2:

class Model1 extends BaseModel
{
    protected $with = ['model2'];

    ...

}

0 个答案:

没有答案