Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @foreach($books as $book)
- <div>{{$book->id}}</div>
- <div>{{$book->title}}</div>
- <div>{{$book->authors->firstname}}</div>
- @endforeach
- class Book extends Eloquent {
- protected $guarded = [];
- public function religions()
- {
- return $this->belongsTo('Religion');
- }
- public function branches()
- {
- return $this->belongsTo('Branch');
- }
- public function authors()
- {
- return $this->belongsTo('Author');
- }
- public function quotes()
- {
- return $this->hasMany('Quote');
- }
- public function chapters()
- {
- return $this->hasMany('Chapter');
- }
- }
- class Author extends Eloquent {
- protected $guarded = [];
- public function books()
- {
- return $this->hasMany('Book');
- }
- public function quotes()
- {
- return $this->hasMany('Quote');
- }
- public function branches()
- {
- return $this->belongsTo('Branch');
- }
- public function religions()
- {
- return $this->belongsTo('Religion');
- }
- }
- class ReligionBranchBookController extends BaseController {
- /**
- * Display a listing of the resource.
- *
- * @return Response
- */
- public function index($religionId, $branchId)
- {
- //
- // $books = Book::where('religion_id', $religionId)->where('branch_id', $branchId)->get();
- $books = Book::all();
- $authors = Author::all();
- // dd($books->toArray());
- return View::make('books.index')
- ->with('religionId', $religionId)
- ->with('branchId', $branchId)
- ->with('books', $books)
- ->with('authors', $authors);
- }
- }
- @extends('layout.main')
- @section('content')
- <h1>Books List!!</h1>
- <table>
- <tr>
- <th>ID</th>
- <th>Title</th>
- <th>Author</th>
- </tr>
- @foreach($books as $book)
- <tr>
- <td>{{$book->id}}</td>
- <td>{{$book->title}}</td>
- <td>{{$book->authors->firstname}}</td>
- </tr>
- @endforeach
- </table>
- @stop
- public function author()
- {
- return $this->belongsTo('Author');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement