I think you're looking for the faceted search ? do a google search for "laravel facet search" and there are many tutorials.
I think this will solve it:
{{{ $result['name'] }}}
on /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php
/**
* Execute the query as a "select" statement.
*
* @param array $columns
* @return array|static[]
*/
public function get($columns = array('*'))
{
return $this->getFresh($columns);
}
As written there, this function returns array.
In your view you are looking for a variable called $results
which is not set. When you are creating your view you are only passing through one variable called $products
in your code: return view('search')->with('products', $results);
Either change your return to be return view('search')->with('results', $results);
or update your view to use $products
rather than $results
.
Let me know if you need more help :-)
Hey thanks for replying :) . I changed it but i cant get the results. The view says either Undefined index: name or if I have it like $product->name it says call to non object. Any ideas?
I would be interested in seeing a var_dump of $results
because from what I can see it should be working unless I have forgotten some idiosyncrasy of how Laravels query builder returns results.
Does your view (blade template) now look like this maneesaj?
<?php
if(isset($products)){ ?>
@foreach($products as $product)
{{{ $product->name }}}
@endforeach
<?php } else {
echo "products not set";
}
?>
(I've kept similar to your original code, simply substituting $results and $result for $products and $product. You could clean a little more using blade syntax for the if/else statements.)
Hey Thanks for the replies. I managed to fix it, it was an issue with the database migrations. Thanks for your help :).
Match your controller and view files with the one given here: https://laravel.io/forum/06-05-2015-newbie-trying-to-create-a-search-function-on-laravel-5 This is a working tutorial on create live search in Laravel 5.5. Basic things should be the same. This could work for you as well. Try out.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community