Hi, could someone suggest me the best way to work with a model, lest say a grades model that I pass to my blade view, and as I go throug it with a ...
For further actions, you may consider blocking this person and/or reporting abuse
I suggest you make your views as dumb as possible. What I mean by that is to do all calculations on the controller and only pass the finished data to the view. Ideally, your views contain as little logic as possible and should only concern themselves with presenting the data to the browser. Something like this should illustrate my point:
If you'd like to share some code, we'd be happy to help some more!
Thanks I added the code to the post.
There might be a collection method you could use on your models to make it easier for you. You could try chaining them, such as where and sum.
$grades->where(‘subject’, ‘history’)->sum(‘score’)
Laravel collections
I already think in that but it will only return the grades for the history subject acumulated, so how I pass all the results to the view, I need to pass all the subjects, like this but I need to group the results by subject and then pass to the view
Always do calculations in your controller, the view only shows data.
Thanks, I already now that, but, how you suggest to do this then if I had a model with the grades but I need to show the calc and pass them to the view, should you suggest to use an array to store the calculations and pass that array to the view them? how you will do it?
Do you have the code so we can see it? when i say "we", i mean this site.
yep I already add it to the post