i intelligente Suchmaschine in meinem Laravel 5 Mit Hilfe dieses Tutorial
https://maxoffsky.com/code-blog/laravel-shop-tutorial-3-implementing-smart-search/
i weil dieses Tutorial für Laravel einige Code Änderungen zu implementieren sind versucht, 4
jetzt ich stecke hier Wenn ich irgendwelche Schlüsselwörter wie cup Typ i Fehler in meinem deleveloper WerkzeugCall to undefined Methode Illuminate Database Abfrage Builder :: Produkte()
Call to undefined method Illuminate\Database\Query\Builder::products()
hier auf Registerkarte Netzwerk bekam ist mein Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Http\Requests;
use App\Product;
use App\Category;
use Response;
class ApiSearchController extends Controller
{
public function appendValue($data, $type, $element)
{
// operate on the item passed by reference, adding the element and type
foreach ($data as $key => & $item) {
$item[$element] = $type;
}
return $data;
}
public function appendURL($data, $prefix)
{
// operate on the item passed by reference, adding the url based on slug
foreach ($data as $key => & $item) {
$item['url'] = url($prefix.'/'.$item['slug']);
}
return $data;
}
public function index()
{
$query = e(Input::get('q',''));
if(!$query && $query == '') return Response::json(array(), 400);
$products = Product::where('published', true)
->where('name','like','%'.$query.'%')
->orderBy('name','asc')
->take(5)
->get(array('slug','name','icon'))->toArray();
$categories = Category::where('name','like','%'.$query.'%')
->has('products')
->take(5)
->get(array('slug', 'name'))
->toArray();
// Data normalization
$categories = $this->appendValue($categories, url('img/icons/category-icon.png'),'icon');
$products = $this->appendURL($products, 'products');
$categories = $this->appendURL($categories, 'categories');
// Add type of data to each item of each set of results
$products = $this->appendValue($products, 'product', 'class');
$categories = $this->appendValue($categories, 'category', 'class');
// Merge all data into one array
$data = array_merge($products, $categories);
return Response::json(array(
'data'=>$data
));
}
}
mein Produkt und Kategorie Modell ist leer, da nichts auf Tutorial
Veröffentlichen Sie Ihr Kategoriemodell. – Abhishek
müssen Sie die Beziehung in Ihren Modellen und der Datenbank einstellen, um das –
zu verwenden Hey mein beider Modell ist leer, was ich dort tippen sollte –