I have this error, and not one of the results that I checked Google looks like my problem.
I have an application with class Deal, User and Matches
The deal has a lot of matches. The user has many matches. The user has many transactions.
I am trying to create a new match using the Deals object
$deal->matches()->create(['user_id'=>$id]);
This is my compliance class, I defined all the necessary relationships
class Match extends Model
{
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');
}
public function user()
{
return $this->belongsTo('App\User');
}
public function deal()
{
return $this->belongsTo('App\Deal');
}
}
And I keep getting this error when I try to create a new match.
QueryException in line Connection.php 647: SQLSTATE [HY000]: General error: 1364 Field 'user_id' has no default value (SQL: insert into matches
( deal_id
) values (1))
I want me to be an empty array, what could be the problem?