dijkr / Copia

Laravel-project with CMS
0 stars 0 forks source link

Creating a partial for the category-banner #20

Closed dijkr closed 1 year ago

dijkr commented 1 year ago

The category has its own banner, but its loaded at:

- product/{product}
- categorie/{category}

Right now, these views are getting the data from the controller seperately, when loading the view. Meaning, that if the content will be modified from the CMS, it need to be done at multiple locations. To make this process straightforward, it need to be done to a partial (Antlers).

dijkr commented 1 year ago

The view banner_cat.antlers.html has been created and the html code is added: `

{{ categoryData.title }}

</div>`

The problem now is, that the data at both routes is done by two different methods. And the question is, if the results are equal. And still, should fetching that data be done by seperated methods?

Probably its better to create its own method and call it from the other methods. Not sure if that is best practice.

dijkr commented 1 year ago

Solved by:

$category = $product->Category;
$category = Category::where('slug', $categorySlug)->first();

Both queries will get the data that both views need. They all load correctly.