Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. @foreach($books as $book)
  2. <div>{{$book->id}}</div>
  3. <div>{{$book->title}}</div>
  4. <div>{{$book->authors->firstname}}</div>
  5. @endforeach
  6.  
  7. class Book extends Eloquent {
  8. protected $guarded = [];
  9.  
  10. public function religions()
  11. {
  12. return $this->belongsTo('Religion');
  13. }
  14.  
  15. public function branches()
  16. {
  17. return $this->belongsTo('Branch');
  18. }
  19.  
  20. public function authors()
  21. {
  22. return $this->belongsTo('Author');
  23. }
  24.  
  25. public function quotes()
  26. {
  27. return $this->hasMany('Quote');
  28. }
  29.  
  30. public function chapters()
  31. {
  32. return $this->hasMany('Chapter');
  33. }
  34. }
  35.  
  36. class Author extends Eloquent {
  37. protected $guarded = [];
  38.  
  39. public function books()
  40. {
  41. return $this->hasMany('Book');
  42. }
  43.  
  44. public function quotes()
  45. {
  46. return $this->hasMany('Quote');
  47. }
  48.  
  49. public function branches()
  50. {
  51. return $this->belongsTo('Branch');
  52. }
  53.  
  54. public function religions()
  55. {
  56. return $this->belongsTo('Religion');
  57. }
  58. }
  59.  
  60. class ReligionBranchBookController extends BaseController {
  61.  
  62. /**
  63. * Display a listing of the resource.
  64. *
  65. * @return Response
  66. */
  67. public function index($religionId, $branchId)
  68. {
  69. //
  70. // $books = Book::where('religion_id', $religionId)->where('branch_id', $branchId)->get();
  71. $books = Book::all();
  72. $authors = Author::all();
  73. // dd($books->toArray());
  74.  
  75. return View::make('books.index')
  76. ->with('religionId', $religionId)
  77. ->with('branchId', $branchId)
  78. ->with('books', $books)
  79. ->with('authors', $authors);
  80. }
  81.  
  82. }
  83.  
  84. @extends('layout.main')
  85.  
  86. @section('content')
  87.  
  88. <h1>Books List!!</h1>
  89.  
  90. <table>
  91. <tr>
  92. <th>ID</th>
  93. <th>Title</th>
  94. <th>Author</th>
  95. </tr>
  96.  
  97. @foreach($books as $book)
  98. <tr>
  99. <td>{{$book->id}}</td>
  100. <td>{{$book->title}}</td>
  101. <td>{{$book->authors->firstname}}</td>
  102. </tr>
  103. @endforeach
  104. </table>
  105.  
  106. @stop
  107.  
  108. public function author()
  109. {
  110. return $this->belongsTo('Author');
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement