我有这个错误,我检查的google搜索结果都没有类似于我的问题.
我有一个类Deal,User和Matches的应用程序
一笔交易有很多比赛.用户有很多匹配.用户有很多优惠.
我正在尝试使用我的Deal对象创建一个新的Match
$deal->matches()->create(['user_id'=>$id]);
Run Code Online (Sandbox Code Playgroud)
这是我的匹配类,我已经定义了所有需要的关系
class Match extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = [];
public $timestamps = false;
public $expired_on = "";
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->matched_on = $model->freshTimestamp();
});
}
public function __construct(){
$d = (new \DateTime($this->matched_on))->modify('+1 day');
$this->expired_on = $d->format('Y-m-d H:i:s');
}
/**
* Get the user that owns the match.
*/
public function user()
{
return $this->belongsTo('App\User');
} …Run Code Online (Sandbox Code Playgroud) 我知道 ES6await特性,我想在我在类中创建的函数中使用它。
它工作得很好,但是当函数是static函数时,它就不是。有什么理由吗?另外,await在static函数内部使用的正确方法是什么?
class MyClass {
resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
static async asyncCall() {
console.log('calling');
var result = await this.resolveAfter2Seconds();
console.log(result);
// expected output: "resolved"
}
}
MyClass.asyncCall();
Run Code Online (Sandbox Code Playgroud) async-await ×1
es6-class ×1
es6-promise ×1
javascript ×1
laravel ×1
laravel-5.4 ×1
mysql ×1
php ×1
static ×1