Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load category data when there isn't a product yet #18

Closed
dijkr opened this issue Jul 26, 2023 · 1 comment
Closed

Load category data when there isn't a product yet #18

dijkr opened this issue Jul 26, 2023 · 1 comment

Comments

@dijkr
Copy link
Owner

dijkr commented Jul 26, 2023

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.

@dijkr
Copy link
Owner Author

dijkr commented Jul 26, 2023

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant