小编Joh*_*vid的帖子

Laravel 5.4字段没有默认值

我有这个错误,我检查的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)

php mysql laravel laravel-5.4

18
推荐指数
7
解决办法
6万
查看次数

“等待 this.method();” 在静态方法中不起作用

我知道 ES6await特性,我想在我在类中创建的函数中使用它。

它工作得很好,但是当函数是static函数时,它就不是。有什么理由吗?另外,awaitstatic函数内部使用的正确方法是什么?

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)

javascript static async-await es6-promise es6-class

6
推荐指数
1
解决办法
2090
查看次数