I have installed the Cviebrock laravel sluggable plugin but I'm having issues querying my database now. I have the slug column and I can see the slug in the URL but it won't display anything from the search results as it was when I was using the category ID as a search term
Here is my category controller:
public function show(Categories $slug)
{
$categoryMenu = Categories::all();
$companies = Company::where('visable', 0)->get();
$categories = Categories::all();
$title = $slug->category;
$products = Products::where('category_id', $slug->id)->get()->groupBy('company_id');
$allCompanies = Products::where('category_id', $slug->id)->groupBy('company_id')->get();
return view('allCategories')->with([
'companies' => $companies,
'allCompanies' => $allCompanies,
'categories' => $categories,
'products' => $products,
'title' => $title,
'categoryMenu' => $categoryMenu,
]);
And the category model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
class Categories extends Model
{
use Sluggable;
/**
* Return the sluggable configuration array for this model.
*
* @return array
*/
public function sluggable()
{
return [
'slug' => [
'source' => 'category'
]
];
}
public function products()
{
return $this->hasMany('App\Products');
}
}
and it's being passed in with:
<li class="nav-item">
<a class="nav-link" href=""></a>
</li>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire