$products = Products::...->get();
if (...) {
$products = ...;
}
В начале года была очень похожая тема — снова писать не хочется, поэтому посмотри, может помочь.
]]>public function post_filter($id) {
$collection = Collection::where('id', '=', $id)->first();
$products = Products::where('type_id', '=', $id)->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->get();
}
if (Input::get('manufacturers') != "" or Input::get('manufacturers') != 0) {
$products = Products::where('type_id', '=', $id)->where('manufacturers_id', '=', Input::get('manufacturers'))->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->where('manufacturers_id', '=', Input::get('manufacturers'))->get();
}
}
if (Input::get('purpose') != "" or Input::get('purpose') != 0) {
$products = Products::where('type_id', '=', $id)->where('purpose', '=', Input::get('purpose'))->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->where('purpose', '=', Input::get('purpose'))->get();
}
if (Input::get('manufacturers') != "" or Input::get('manufacturers') != 0) {
$products = Products::where('type_id', '=', $id)->where('manufacturers_id', '=', Input::get('manufacturers'))->where('purpose', '=', Input::get('purpose'))->get();
}
}
if (Input::get('min') != "" or Input::get('min') != 0 or Input::get('max') != "" or Input::get('max') != 0) {
$products = Products::where('type_id', '=', $id)->where_between('price', Input::get('min'), Input::get('max'))->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->where_between('price', Input::get('min'), Input::get('max'))->get();
}
if (Input::get('manufacturers') != "" or Input::get('manufacturers') != 0) {
$products = Products::where('type_id', '=', $id)->where('manufacturers_id', '=', Input::get('manufacturers'))->where_between('price', Input::get('min'), Input::get('max'))->get();
}
if (Input::get('purpose') != "" or Input::get('purpose') != 0) {
$products = Products::where('type_id', '=', $id)->where('purpose', '=', Input::get('purpose'))->where_between('price', Input::get('min'), Input::get('max'))->get();
}
}
if (Input::get('min-more') != "" or Input::get('min-more') != 0) {
$products = Products::where('type_id', '=', $id)->where('price', '>', Input::get('min-more'))->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->where('price', '>', Input::get('min-more'))->get();
}
if (Input::get('manufacturers') != "" or Input::get('manufacturers') != 0) {
$products = Products::where('type_id', '=', $id)->where('manufacturers_id', '=', Input::get('manufacturers'))->where('price', '>', Input::get('min-more'))->get();
}
if (Input::get('purpose') != "" or Input::get('purpose') != 0) {
$products = Products::where('type_id', '=', $id)->where('purpose', '=', Input::get('purpose'))->where('price', '>', Input::get('min-more'))->get();
}
}
if (Input::get('max-more') != "" or Input::get('max-more') != 0) {
$products = Products::where('type_id', '=', $id)->where('price', '>', Input::get('max-more'))->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->where('price', '>', Input::get('max-more'))->get();
}
if (Input::get('manufacturers') != "" or Input::get('manufacturers') != 0) {
$products = Products::where('type_id', '=', $id)->where('manufacturers_id', '=', Input::get('manufacturers'))->where('price', '>', Input::get('max-more'))->get();
}
if (Input::get('purpose') != "" or Input::get('purpose') != 0) {
$products = Products::where('type_id', '=', $id)->where('purpose', '=', Input::get('purpose'))->where('price', '>', Input::get('max-more'))->get();
}
}
if (Input::get('formats') != "" or Input::get('formats') != 0) {
$products = Products::where('type_id', '=', $id)->where('id', '=', Input::get('formats'))->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->where('id', '=', Input::get('formats'))->get();
}
if (Input::get('manufacturers') != "" or Input::get('manufacturers') != 0) {
$products = Products::where('type_id', '=', $id)->where('manufacturers_id', '=', Input::get('manufacturers'))->where('id', '=', Input::get('formats'))->get();
}
if (Input::get('purpose') != "" or Input::get('purpose') != 0) {
$products = Products::where('type_id', '=', $id)->where('purpose', '=', Input::get('purpose'))->where('id', '=', Input::get('formats'))->get();
}
}
if (Input::get('texture') != "" or Input::get('texture') != 0) {
$products = Products::where('type_id', '=', $id)->where('texture', '=', Input::get('texture'))->get();
if (Input::get('country') != "" or Input::get('country') != 0) {
$products = Products::where('type_id', '=', $id)->where('country_id', '=', Input::get('country'))->where('texture', '=', Input::get('texture'))->get();
}
if (Input::get('manufacturers') != "" or Input::get('manufacturers') != 0) {
$products = Products::where('type_id', '=', $id)->where('manufacturers_id', '=', Input::get('manufacturers'))->where('texture', '=', Input::get('texture'))->get();
}
if (Input::get('purpose') != "" or Input::get('purpose') != 0) {
$products = Products::where('type_id', '=', $id)->where('purpose', '=', Input::get('purpose'))->where('texture', '=', Input::get('texture'))->get();
}
if (Input::get('min') != "" or Input::get('min') != 0 or Input::get('max') != "" or Input::get('max') != 0) {
$products = Products::where('type_id', '=', $id)->where_between('price', Input::get('min'), Input::get('max'))->where('texture', '=', Input::get('texture'))->get();
}
}
$texture = Texture::where('collection_id', '=', 1)->get();
$formats = Formats::order_by('format', 'asc')->get();
$country = Country::all();
$manufacturers = Manufacturers::all();
$phone = Contact::where('id', '=', 1)->first();
return View::make("home.products")->with(array('products' => $products, 'texture' => $texture, 'formats' => $formats, 'manufacturers' => $manufacturers, 'country' => $country, 'collection' => $collection, 'id' => $id, 'phone' => $phone));
}
код еще можно посмотреть здесь http://paste.laravel.com/110j
]]>