Laravel 8 Helpers vs Controllers Performance

Published

I wonder if there are any differences between putting a function in helpers or just putting it on controllers?
For example, a function to count how much data in database,
In helpers the code looks like:

function countData($status = 'active')
{
    $data = Models::where('status', 'like', $status)->count();
    return $data;
}

And in controllers the code looks like:

$status = 'active';
$countData = Models::where('status', 'like', $status)->count();
return view('some.view', compact('countData');

Which one is the best, using helpers or controllers?
Is there any way to check the performances between those two?
Thanks.

Source: Laravel

Published
Categorised as laravel, laravel-8 Tagged ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq