Невозможно получить связанное значение из другой таблицы, используя отношение Laravel Mongo DB ко многим
У меня есть две таблицы Posted_jobs(Модель:PostedJobs) и пользователи (Модель: Пользователь). В пользовательской модели я определил функцию AppliedJobs для получения прикладных заданий пользователя.
public function AppliedJobs(){
return $this->belongsToMany('App\PostedJob');
}
В модели PostedJob я определил функцию "Кандидаты" для получения кандидатов на определенную работу.
public function Applicants(){
return $this->belongsToMany('App\User');
}
Данные в коллекции пользователей Mongodb
{
"_id" : ObjectId("5abb5e234dd49f36b776c1b2"),
"Type" : "Worker",
"firstname" : "Joshep",
"lastname" : "Anthony",
"email" : "accenza50@gmail.com",
"category" : "5ab3953b231f000d790ce4d3",
"gender" : "M",
"service_area" : "",
"status" : "A",
"verified" : "Y",
"password" : "$2y$10$Et3fZogpX31sXacSSvrlk.qSP7nTCg6pvrRtPaoK8Vq/WrWDPwmuu",
"email_token" : "NDAyNjc4OGFjY2VuemE1MEBnbWFpbC5jb20xNDk2ODcw",
"updated_at" : ISODate("2018-04-02T15:01:07.000Z"),
"created_at" : ISODate("2018-03-28T09:19:31.000Z"),
"remember_token" : "H9XF29QvbIosPCccL143SJKJt0TZlziF9JwoHbOqyV77f91M55LcQHWe7fct",
"address" : "Maula Ali, Taltala, Kolkata, West Bengal, India",
"contact_no" : "8981527733",
"profilepic" : "profile_152265817444.jpeg",
"posted_job_ids" : [
ObjectId("5abcf44b4dd49f0bbd1ae0b2"),
ObjectId("5abe0f9d4dd49f24fc65c292")
]}
И это в коллекции posts_jobs есть
{
"_id" : ObjectId("5abcf44b4dd49f0bbd1ae0b2"),
"category" : "5ab3881c231f000d790ce4d2",
"date" : "02/04/2018",
"time" : "08:40:58",
"address" : "Badshahpur, Sector 66, Gurugram, Haryana, India",
"city" : "Gurugram",
"zip" : "712503",
"title" : "Domestic Help",
"description" : "Lorem Ipsum is simply dummy text of the printing and typesetting industry. try's standard.Lorem Ipsum is simply dummy text of the printing and typesetting industry. try's standard.",
"notes" : "Lorem Ipsum is simply dummy text of the printing and typesetting industry. try's standard.Lorem Ipsum is simply dummy text of the printing and typesetting industry. try's standard.",
"duration" : "4",
"price" : "10",
"lat" : "28.3982709",
"long" : "77.05356800000004",
"status" : "A",
"completion_status" : "N",
"is_emergency" : "N",
"updated_at" : ISODate("2018-03-30T09:55:56.000Z"),
"created_at" : ISODate("2018-03-29T14:12:27.000Z"),
"_method" : "PUT",
"posted_by" : "5ab2681c4dd49f130d39c303",
"user_ids" : [
ObjectId("5abb5e234dd49f36b776c1b2")
]}
{
"_id" : ObjectId("5abe0f9d4dd49f24fc65c292"),
"category" : "5ab3953b231f000d790ce4d3",
"date" : "06/04/2018",
"time" : "09:31:42",
"address" : "Amsterdam, Netherlands",
"city" : "Amsterdam",
"zip" : "712523",
"title" : "Need and electrician",
"description" : "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the",
"notes" : "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the",
"duration" : "2",
"price" : "15",
"lat" : "52.3702157",
"long" : "4.895167899999933",
"slug" : "need-and-electrician",
"status" : "A",
"completion_status" : "N",
"is_emergency" : "N",
"posted_by" : "5ab2681c4dd49f130d39c303",
"updated_at" : ISODate("2018-03-30T11:18:22.000Z"),
"created_at" : ISODate("2018-03-30T10:21:17.000Z"),
"_method" : "PUT",
"user_ids" : [
ObjectId("5abb5e234dd49f36b776c1b2")
]}
Однако, когда я использую функцию AppliedJob() для пользовательского экземпляра, я не получаю задания для пользователя.