doctrine2 - JSON Web Token only work in Laravel with Eloquent model -


i using laravel , want use json web token (jwt). download tymon vendor. when tried generate token raise me error said model not instance of eloquent model. check vendor code , saw in eloquentuseradapter:

<?php  namespace tymon\jwtauth\providers\user;  use illuminate\database\eloquent\model;  class eloquentuseradapter implements userinterface {     /**      * @var \illuminate\database\eloquent\model      */     protected $user;      /**      * create new user instance      *      * @param  \illuminate\database\eloquent\model  $user      */     public function __construct(model $user)     {         $this->user = $user;     }      /**      * user given key, value      *      * @param  mixed  $key      * @param  mixed  $value      * @return illuminate\database\eloquent\model      */     public function getby($key, $value)     {         return $this->user->where($key, $value)->first();     } } 

my problem here adapter use eloquent model injection. using doctrine models. questions are:

  1. is possible change adapter return new model (my doctrine model). asking because new in php , laravel , saw eloquentuseradapter used in other places in vendor.
  2. if create new adapter think have return eloquent model, how can redefine model , reuse other classes , methods of vendor?

any clue?

  1. yes, can:

use app\entities\user; use doctrine\orm\entitymanagerinterface; use tymon\jwtauth\providers\user\userinterface;  class doctrineuseradapter implements userinterface {     protected $em;      public function __construct(user $user, entitymanagerinterface $em)     {         $this->em = $em;     }      public function getby($key, $value)     {         return $this->em->find('app\entities\user', $value);     } } 

you can inject entitymanagerinterface object second parameter, first parameter user model type 'providers.user' in jwt.php configuration, why? @ code in jwtauthserviceprovider.php:

/**  * register bindings user provider.  */ protected function registeruserprovider() {     $this->app['tymon.jwt.provider.user'] = $this->app->share(function ($app) {         return $app->make($this->config('providers.user'), [$app->make($this->config('user'))]);     }); } 

my simple user model:

use doctrine\orm\mapping orm;  /**  * users *  * @orm\table(name="users")  * @orm\entity  */ class user implements \illuminate\contracts\auth\authenticatable {     use \laraveldoctrine\orm\auth\authenticatable;      /**      *      * @var integer *      * @orm\column(name="id", type="integer", nullable=false)      * @orm\id      * @orm\generatedvalue(strategy="identity")      */      public $id; } 
  1. you can in version 1.0.0. more problem: https://github.com/tymondesigns/jwt-auth/issues/343

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -