D
D
D44k2017-07-22 13:29:52
Laravel
D44k, 2017-07-22 13:29:52

Is it correct to call a model method from a template?

Is it correct to call the model method (which fetches the menu from the base Menu::getMenu() ) directly from the blade template to display the menu.

@section('menu')
           @include('layouts.admin.partials.menu', array('menus' => Menu::getMenu(), 'parent_id' => 0))
@show

Does it break MVC?
Or pass a variable from the controller to the template each time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LightAir, 2017-07-24
@LightAir

Of course, everyone interprets MVC in their own way, however, I do not recommend doing this. If Menu::getMenu() will be called in several places, then in case of changing the data or the name of the model / method, then you will have to look for all calls in the templates. If you need to test, then there will also be problems.

V
Victor, 2017-07-22
@v_decadence

I don’t see anything shameful, it’s not a code footcloth. I do like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question