I am using MongoDB library in Laravel 5.3. I have two collections in MongoDB and I want to make a hasMany relation b/w them.
in Mongo Eloquent when creating Many to Many relationships you dont need to have a pivot table, thats SQL mindset, in mongo-eloquent many to many relations the foreign keys are stored in arrays. So the models should look like this:
belongsToMany('App\Models\Task');
}
}
belongsToMany('App\Models\Employee');
}
}
Also you should load the relations before trying to retrieve them
$employee= Employee::with('tasks')->find('586ca8c71a72cb07a681566d')->tasks;
You can save the relation the same way you do it in the hasMany relation
$employee->tasks()->save(new Task());