/** * Display a listing of the books resource. * * @return \Illuminate\Http\Response */ public function index() { $books = Book::orderBy('id', 'desc')->paginate(10); $books->setPath(action('BooksController@index')); if (!empty(Input::get('page')) && Input::get('page') > $books->lastPage()) { return redirect()->action('BooksController@index', ['page' => $books->lastPage()]); } $title = 'Lista książek'; return view('books.index', compact('books', 'title')); }
/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $books = Book::orderBy('created_at', 'desc')->take(9)->get(); $activeUser = Auth::user(); if ($activeUser) { $this->notif(); } if ($this->notif) { return view('home', ['books' => $books, 'user' => $activeUser, 'notif' => $this->notif, 'length' => $this->length]); } return view('home', ['books' => $books, 'user' => $activeUser]); }
/** * Displays a listing of all the books available and allows their sorting as well. * * @return \Illuminate\Http\Response */ public function index() { $sortBy = Input::get('sortBy'); $order = Input::get('order'); if ($sortBy and $order == 'asc') { $books = Book::orderBy($sortBy, 'ASC')->get(); } elseif ($sortBy and $order == "desc") { $books = Book::orderBy($sortBy, 'DESC')->get(); } else { $books = Book::all(); } return view('home')->with('books', $books); }
function getExample0() { $books = \App\Book::orderBy('id', 'ASC')->get(); //$first = \App\Book::orderBy('id','ASC')->first(); //$last = \App\Book::orderBy('id','DESC')->first(); $first = $books->first(); $last = $books->last(); dump($first->toArray()); dump($last->toArray()); }
/** * Responds to requests to GET /books */ public function getIndex(Request $request) { $books = \App\Book::orderBy('id', 'DESC')->get(); dump($books->toArray()); return view('books.index')->with('books', $books); }
/** * Display a listing of the resource. * * @return \Illuminate\View\View */ public function index() { $books = Book::orderBy('created_at', 'desc')->paginate(3); return view('home', compact('books')); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $listItem = Book::orderBy('created_at', 'DESC')->paginate(ITEM_PER_PAGE); //$listItem = Book::orderBy('created_at', 'DESC')->take(5)->get()->toArray(); return view('home.home', compact('listItem')); }
function getExample8() { $book = \App\Book::orderBy('id', 'DESC')->first(); dump($book->toArray()); echo 'The book title is' . $book->title . '<br/>'; $book = \App\Book::first(); $author = $book->author; echo $book->title . ' was written by ' . $author->first_name . ' ' . $author->last_name; dump($book->toArray()); return 'Example 8'; }
/** * Querying on the Model vs. the Collection */ function getExample6() { // Query Responsibility $books = \App\Book::orderBy('id', 'DESC')->get(); $first = $books->first(); $last = $books->last(); //$first = \App\Book::orderBy('id','ASC')->first(); //$last = \App\Book::orderBy('id','DESC')->first(); dump($books); dump($first); dump($last); }
public function index() { // $books = Book::orderBy('updated_at','desc')->take(20)->get(); $books = Book::orderBy('updated_at', 'desc')->paginate(3); return view('home')->with('books', $books); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $books = Book::orderBy('book_title', 'desc')->get(); return view('books.index', compact('books')); }
/** * Utility Methods - Eager Loading Techniques. more gonna be added */ // Skip nothing and take 3 records Route::get('book_skip_and_take', function () { $books = \App\Book::skip(0)->take(2)->get(); return $books; }); // Skip the first two records and take the next 3 records Route::get('book_skip_and_take_again', function () { $books = \App\Book::skip(2)->take(3)->get(); return $books; }); // Order the books in ascending order according to their title, `desc` is also an alternative Route::get('book_orderBy', function () { $books = \App\Book::orderBy('title', 'asc')->get(); return $books; }); // Group the books by the price...e.g if 3 books have thesame price, it groups them together as one Route::get('book_groupBy', function () { $books = \App\Book::groupBy('price')->get(); return $books; }); // Return all books that have pages_count less than 150 Route::get('book_having', function () { $books = \App\Book::having('pages_count', '<', 150)->get(); return $books; }); // Return all books including the ones that have been deleted // Listen: this requires your migration already has $table->softDeletes(); // and your Model also uses the Eloquent SoftDeletes trait