Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. {
  2. "_id" : ObjectId("586ca8c71a72cb07a681566d"),
  3. "employee_name" : "John",
  4. "employee_description" : "test description",
  5. "employee_email" : "john@email.com",
  6. "updated_at" : "2017-01-04 11:45:20",
  7. "created_at" : "2017-01-04 11:45:20"
  8. },
  9. {
  10. "_id" : ObjectId("586ca8d31a72cb07a6815671"),
  11. "employee_name" : "Carlos",
  12. "employee_description" : "test description",
  13. "employee_email" : "carlos@email.com",
  14. "updated_at" : "2017-01-04 11:45:20",
  15. "created_at" : "2017-01-04 11:45:20"
  16. }
  17.  
  18. {
  19. "_id" : ObjectId("586ccbcf1a72cb07a6815b04"),
  20. "task_name" : "New Task",
  21. "task_description" : "test description",
  22. "task_status" : 1,
  23. "task_created_at" : "2017-04-01 02:17:00",
  24. "task_updated_at" : "2017-04-01 02:17:00"
  25. },
  26. {
  27. "_id" : ObjectId("586cd3261a72cb07a6815c69"),
  28. "task_name" : "2nd Task",
  29. "task_description" : "test description",
  30. "task_status" : 1,
  31. "task_created_at" : "2017-04-01 02:17:00",
  32. "task_updated_at" : "2017-04-01 02:17:00"
  33. }
  34.  
  35. {
  36. "_id" : ObjectId("586cd0cb1a72cb07a6815bf3"),
  37. "employee_task_employee_id" : "586ca8c71a72cb07a681566d",
  38. "employee_task_task_id" : "586ccbcf1a72cb07a6815b04",
  39. "status" : 1
  40. },
  41. {
  42. "_id" : ObjectId("586cd7851a72cb07a6815d7d"),
  43. "employee_task_employee_id" : "586ca8c71a72cb07a681566d",
  44. "employee_task_task_id" : "586cd3261a72cb07a6815c69",
  45. "status" : 1
  46. }
  47.  
  48. <?php
  49. namespace AppModels;
  50.  
  51. use JenssegersMongodbEloquentModel as Eloquent;
  52.  
  53. class Employee extends Eloquent {
  54.  
  55. protected $collection = 'employee';
  56. protected $primaryKey = '_id';
  57.  
  58. public function tasks()
  59. {
  60. return $this->hasMany('AppModelsTask');
  61. }
  62. }
  63.  
  64. <?php
  65. namespace AppModels;
  66.  
  67. use JenssegersMongodbEloquentModel as Eloquent;
  68.  
  69. class Task extends Eloquent {
  70.  
  71. protected $collection = 'task';
  72. protected $primaryKey = '_id';
  73.  
  74. public function employees()
  75. {
  76. return $this->belongsToMany('AppModelsEmployee');
  77. }
  78. }
  79.  
  80. public function EmployeeData($data)
  81. {
  82. $employee= Employee::find('586ca8c71a72cb07a681566d')->tasks;
  83. echo "<pre>";
  84. print_r($employee);
  85. }
  86.  
  87. IlluminateDatabaseEloquentCollection Object
  88. (
  89. [items:protected] => Array
  90. (
  91. )
  92.  
  93. )
  94.  
  95. <?php namespace AppModels;
  96.  
  97. use JenssegersMongodbEloquentModel as Eloquent;
  98.  
  99. class Employee extends Eloquent {
  100.  
  101. protected $collection = 'employee';
  102. protected $primaryKey = '_id';
  103.  
  104. public function tasks()
  105. {
  106. return $this->belongsToMany('AppModelsTask');
  107. }
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114. <?php namespace AppModels;
  115.  
  116. use JenssegersMongodbEloquentModel as Eloquent;
  117.  
  118. class Task extends Eloquent {
  119.  
  120. protected $collection = 'task';
  121. protected $primaryKey = '_id';
  122.  
  123. public function employees()
  124. {
  125. return $this->belongsToMany('AppModelsEmployee');
  126. }
  127. }
  128.  
  129. $employee= Employee::with('tasks')->find('586ca8c71a72cb07a681566d')->tasks;
  130.  
  131. $employee->tasks()->save(new Task());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement