If we want to search for information in our application, it might be useful to perform the search asynchronously. That way, the user won't have to be taken to a new page and have all the assets refreshed. Using Laravel and JavaScript, we can perform this search in a very simple manner.
To complete this recipe, follow these steps:
In the
controllers
directory, create a file namedSearchController.php
:<?php class SearchController extends BaseController { public function getIndex() { return View::make('search.index'); } public function postSearch() { $return = array(); $term = Input::get('term'); $books = array(array('name' => 'Alice in Wonderland', 'author' => 'Lewis Carroll'),array('name' => 'Tom Sawyer', 'author' => 'Mark Twain'),array('name' => 'Gulliver\'s Travels', 'author' =>'Jonathan Swift'),array('name' => 'The Art of War'...