1

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()

Ardent error message

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

Community
  • 1
  • 1
Zaki Aziz
  • 3,592
  • 11
  • 43
  • 61

1 Answers1

0

You haven't defined the rules for one or more of your models that extend Ardent.

class Whatever extends \LaravelArdent\Ardent\Ardent {
   public static $rules = [];
}

Line 821 shows that we're looking for an array called $ruleset that we can't find.

Sturm
  • 4,105
  • 3
  • 24
  • 39
  • I have not added `$rules` to the question above but I do have them in my model file. I will update the question to reflect this. – Zaki Aziz Jan 15 '16 at 17:31