A
A
Andr Lw12014-09-16 20:33:04
symfony
Andr Lw1, 2014-09-16 20:33:04

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

2 answer(s)
V
Vyacheslav Plisko, 2014-09-23
@lw1

Why do you need several options if you can combine them into one query
if you want, you can filter everything, etc.

I
Ivan, 2014-09-17
@0neS

And here Symfony?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question