Home > Blockchain >  Querying the database from Blade components classes
Querying the database from Blade components classes

Time:02-16

Is it good or bad practice to do database queries inside of Blade components' classes?

In my case, I have some components that always need the same dynamic data. For example: a component that displays a list of active retail points, and I find it pretty inconvenient to cascade the Collection from the Controller to the Component.

CodePudding user response:

It depends on what you are trying to do. But generally speaking, even though executing queries in the blade is possible, it’s not the best thing to do as it may lead to unnecessary extra loops and queries.

I won't go into details here. But if you are interested you can read about it in this article.

If you have data that you want to be bound to a view each time that view is rendered, you can use View Composer to do just that.

CodePudding user response:

I never use query in blade. If i want to dynamic data in my page, I use ajax or axios

  • Related