I’m trying to display featured game in my home page but i’m getting the error :
Call to undefined method IlluminateDatabaseEloquentBuilder::links()
when i’m changing in the HomeController :
From
$home = Product::inRandomOrder()->paginate($pagination);
To
$home = Product::where('featured', 'true');
HomeController
public function public(){
$pagination = 9;
$categories = Category::all();
if (request()->category) {
$home = Product::where('category_id', request()->category)->paginate($pagination);
$categoryName = optional($categories->where('id', request()->category)->first())->name;
}
else {
$home = Product::where('featured', 'true');
$categoryName = 'Featured';
}
return view('home.index')->with([
'home' => $home,
'categories' => $categories,
'categoryName' => $categoryName,
'mode' => 'public'
]);
}
2020_04_09_073846_create_products_table
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->integer('category_id')->unsigned();
$table->string('name');
$table->string('slug');
$table->string('description');
$table->string('releaseDate');
$table->boolean('featured')->default(false);
$table->float('price');
$table->timestamps();
});
{{ $homes->links() }}
in the home.blade.php (at the end of the html of course)
So every game is at 0, so it should be display a page empty whithout any game.
The pagination works fine without changing the line in the HomeController but when i’m changing to $home = Product::where('featured', 'true');
. It’s not working.
What I tried :
Put 5, 10 or 20 games at 1 in the featured column but same error.
Put $home = Product::where('featured', 'true')->paginate($pagination);
but it shows me every game that i have…
Thanks for your help.
Advertisement
Answer
Try this:
Product::where('featured',true)