Answer the question
In order to leave comments, you need to log in
How to search/filter posts in Laravel 4?
Good evening!
There is a blog on Laravel 4. Posts have the following fields (in the database):
1. type_Id
2. area_id
Also, there is a table types and areas that store data (id, name).
It is necessary to make search, through select. The frontend part has already been done, but how to display the result if we have several values?
// SearchControll.php
public function search(){
$data = Input::all();
$results = Search::get($data);
return View::make('search', array(
'results' => $results
));
// Search.php - model
public static function get($data){
$result = array(
Post::where('type_id', 'LIKE', $data['type'])->get(),
Post::where('area_id', 'LIKE', $data['area'])->get()
)
return $result;
}
// search.blade.php
@extends('template.template')
@section('content')
@foreach($results as $result)
<h2>{{ $result->title }}</h2>
<p>{{ $result->desc }}</p>
@endforeach
@stop
Answer the question
In order to leave comments, you need to log in
Why do you need several options if you can combine them into one query
if you want, you can filter everything, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question