I am using Laravel 5. if I have written a function on Model class and takes it's object by laravel eloquent to any view file like cars.blade.php
file and now if I call any model function from cars.blade.php
Like Model Class
Car.php
public function totalModels() {
return App\Models\CarModel::where('id',$this->modelId)->count();
}
Cars.blade.php
<span>Available Models : {{ $car->totalModels() }}</span>
So My Questions are
When this function will call ?
Is this function slow the page ?
Is this a best practice to do it ?
if there is any foreach loop then how will this function will behave for each object ?
Thanks