Created
January 6, 2014 20:56
-
-
Save anonymous/8289692 to your computer and use it in GitHub Desktop.
Creating Search Facility on website (but not working)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Route */ | |
Route::get('/search/{q}', 'HomeController@search'); | |
/* Form from web page */ | |
<form class="navbar-form navbar-left" role="search" action="/search/" method="post"> | |
<div class="input-group"> | |
<input type="text" class="form-control" placeholder="Search Programmes" name="1"> | |
<span class="input-group-btn"> | |
<input type="submit" class="btn btn-primary" value="Search"> | |
</span> | |
</div><!-- /input-group --> | |
</form> | |
/* Controller */ | |
public function search($q) | |
{ | |
$q = Input::get('term'); | |
$searchTerms = explode(' ', $q); | |
$query = DB::tables('wc_program'); | |
foreach($searchTerms as $term) | |
{ | |
$query->where('JobRef', 'LIKE', '%'. $term .'%'); | |
} | |
$results = $query->get(); | |
} | |
/* Model (just in case) */ | |
class Search extends Eloquent { | |
protected $table = 'wc_program'; | |
public $timestamps = false; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment