Guest User

Untitled

a guest
Aug 7th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. public function orders(){
  2. return $this->hasMany(Order::class);
  3. }
  4.  
  5. public function user(){
  6. return $this->belongsTo(User::class);
  7. }
  8. public function product(){
  9. return $this->belongsTo(Product::class);
  10. }
  11.  
  12. {
  13. id: 11,
  14. quantity: 2,
  15. customer: {
  16. id: 6,
  17. name: "saging",
  18. email: "saging@gmail.com",
  19. role_id: 3,
  20. },
  21. items: {
  22. id: 7,
  23. name: "Pellentesque semper",
  24. description: "raesent sit amet elementum purus. ",
  25. price: "72.21",
  26. cover_image: "7CPVS7yjqba9iJ7J.jpg",
  27. }
  28. },
  29.  
  30. {
  31. id: 12,
  32. quantity: 2,
  33. customer: {
  34. id: 6,
  35. name: "saging",
  36. email: "saging@gmail.com",
  37. role_id: 3,
  38. },
  39. items: {
  40. id: 3,
  41. name: "Donec nec mattis ligula",
  42. description: "Pellentesque semper, augue at aliquet tincidunt",
  43. price: "33.21",
  44. cover_image: "ZJbbzjPwDXrcbkwi.jpg",
  45. }
  46. }
  47.  
  48. $products = Order::with('user','product');
  49. return OrdersResource::collection($products->paginate(5));
  50.  
  51. {
  52. id: 12,
  53. quantity: 2,
  54. customer: {
  55. id: 6,
  56. name: "saging",
  57. email: "saging@gmail.com",
  58. role_id: 3,
  59. },
  60. items: [
  61. {
  62. id: 3,
  63. name: "Donec nec mattis ligula",
  64. description: "Pellentesque semper, augue at aliquet tincidunt",
  65. price: "33.21",
  66. cover_image: "ZJbbzjPwDXrcbkwi.jpg",
  67. },
  68. {
  69. id: 7,
  70. name: "Pellentesque semper",
  71. description: "raesent sit amet elementum purus. ",
  72. price: "72.21",
  73. cover_image: "7CPVS7yjqba9iJ7J.jpg",
  74. }
  75. ]
  76. }
Add Comment
Please, Sign In to add comment