I have an Ardent v3.3.0 model like this:
class Company extends Ardent
{
protected $fillable = [
'name',
'address'
];
public static $rules = [
'name' => 'required',
'address' => 'string'
];
public function workers()
{
return $this->belongsToMany('App\Worker')->withPivot('worker_type');
}
}
Another model that goes something like this:
class Worker extends Ardent
{
protected $fillable = [
'name',
];
public static $rules = [
'name' => 'required',
];
public function company()
{
return $this->belongsToMany('App\Company')->withPivot('worker_type');
}
}
In my controller I'm calling a save method like this:
$worker = New Worker;
$worker->name = "Jane Smith";
$company = Company::find($id);
$company->workers()->save($worker, ['worker_type' => 'contractor'];
According to Laravel's and Ardent's docs I'm correctly forming my relationships but Ardent throws an error: ErrorException in Ardent.php line 821: Invalid argument supplied for foreach()
What's causing this error? Is it a bug in my code or Ardent's?
Note: I'm using Ardent version 3.3.0, the issue disappears when I roll back to version 3.0.0