re: Someone could help me about calculations in blade views? VIEW POST

VIEW FULL DISCUSSION
 

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:

// Strive to make views as simple as this.
@foreach ($grades as $grade)
    {{ $grade }}
@endforeach

// And do all the heavy lifting in the controller
public function index()
{
    $grades = Grade::someQuery()->all();
    $computed = $grades->map(function ($grade) { /** do your work here */ });

    return view('grades.index', ['grades' => $computed]);
}

If you'd like to share some code, we'd be happy to help some more!

 
code of conduct - report abuse