Simple search form
@if (count($pages) > 0)
@foreach ($pages as $p)
<div class="rs">
<a href="/page/{{ $p->slug }}">{{ $p->title }}</a>
</div>
@endforeach
@else
<p>Ничего не найдено.</p>
@endif
{{ Form::open(array('method' => 'GET', 'action' => 'ComplaintController@home')) }}
{{ Form::input('search', 'q', null, array('placeholder' => 'Найти...', 'class' => 'form-control')) }}
{{ Form::submit('Найти', array('class' => 'btn btn-default')) }}
{{ Form::close() }}
public function home() {
$query = Input::get('q');
if (isset($query)) {
// validation
$validator = new SearchFormValidator(array('q' => $query));
if ($validator->fails()) {
return Redirect::action('ComplaintController@home')->withErrors($validator->errors());
}
}
if ($query) {
$complaints = $this->complaint->where('title', 'LIKE', "%$query%")->get();
} else {
$complaints = $this->complaint->getAll();
}
return View::make('front.home')->with('complaints', $complaints);
}