Closed dijkr closed 1 year ago
The solution was to import the Category-model within the ProductController.
Then the category data can be directly loaded from the model, without the need of a relation with a product.
use App\Models\Product;
use App\Models\Category;
// Find the category
$categorySlug = basename($request->getRequestUri());
// Get the category data
$categoryData = Category::where('slug', $categorySlug)->first();
The /categorie/{category} will not load if there isn't a product within that specific category in the database yet. This is because the category-data is fetched by using the product relation with the category.