I have a third-party open-source Laravel application with a large number of views that use almost identical hard-coded HTML/PHP definitions. By "hard-coded," I mean that each item's div/block has its hard-coded classes etc., so every displayed item, for example in a list, is identical in its structure, except for the individual fields/values being rendered. The same is true for the app's many forms.
Is there a best practice for generalizing this by using small, generalized application-wide "item" blades and passing parameters for individual values and rendering?
Many thanks for your consideration.
Hello relume,
You could utilize Laravel Blade Components to create a reusable view component.
For example, you could make a Blade component for an item in a list and pass the data like this:
<x-item :title="$title" :description="$description" />
When it comes to the variation problem, you could create a specialize set of item component and logic to further fits your needs. For example:
<x-item-user :name="$name" :contact="$contact" />
<x-item-product :title="$title" :price="$price" />
I don't know if its considered best practices or not, but it says much about how I would approach the situation. Hope it helps.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community