我正在使用Laravel 5.0开发web apis,但我对查询有疑问.我的课程是:
class Event extends Model {
protected $table = 'events';
public $timestamps = false;
public function participants()
{
return $this->hasMany('App\Participant', 'IDEvent', 'ID');
}
public function owner()
{
return $this->hasOne('App\User', 'ID', 'IDOwner');
}
}
Run Code Online (Sandbox Code Playgroud)
和
class Participant extends Model {
protected $table = 'participants';
public $timestamps = false;
public function user()
{
return $this->belongTo('App\User', 'IDUser', 'ID');
}
public function event()
{
return $this->belongTo('App\Event', 'IDEvent', 'ID');
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我希望用特定的partecipant获取所有事件.我尝试过:
Event::with('participants')->where('IDUser', 1)->get();
Run Code Online (Sandbox Code Playgroud)
但where条件适用于Event的类而不是Partecipants.这给了我一个例外:
Participant::where('IDUser', 1)->event()->get();
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样写:
$list = Participant::where('IDUser', 1)->get();
for($item …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android应用程序,我对令牌和刷新令牌有点困惑.基本上现在,在用户使用移动号码和SMS发送的代码登录后,认证服务器返回将用于访问所有api的访问令牌.对于身份验证服务器,我使用了Laravel和jwt-auth库.当访问令牌过期时,我将使用存储在AccountManager中的用户凭证来询问新的令牌.这是实现此身份验证的正确方法吗?
或者我错过了刷新令牌,当过期时我会问一个新的访问令牌?
在此先感谢Daniele
android ×1
eloquent ×1
jwt ×1
laravel ×1
php ×1
refresh ×1
relationship ×1
token ×1
where-clause ×1