O'Reilly logo

Laravel Application Development Blueprints by Halil İbrahim Yılmaz, Arda Kılıçdağı

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Listing books

First, we need to list our products. To do that, we need to create a controller, which is named BookController. Let's create a file under app/controllers/ and save it with the name BookController.php. The controller code should look like the following:

<?php
class BookController extends BaseController{

  public function getIndex()
  {

    $books = Book::all();

    return View::make('book_list')->with('books',$books);

  }
}

The code simply fetches all the books from our books table and passes the data book_list.blade.php template with the $books variable. So we need to create a template file under app/controllers/, which is named as book_list.blade.php. Before doing this we need a layout page for our templates. Working with layout files is very helpful ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required