Reputation: 1818
Is extending model to a controller a good idea?
Like say I want to make my functions in the model protected instead of public and then extend my model to the controller so that the controller can still call those functions?
Is it a good thing to do? Or should I just leave them public?
Upvotes: 0
Views: 850
Reputation: 5387
I can't imagine how controllers could "extend" your model. You can extend Eloquent models for example, and make inherited models like:
class ModelB extends ModelA
{
// code
}
class ModelA extends Eloquent
{
protected $something;
//code
}
and then use them in the controller accordingly. Your controllers extend a different class, BaseController and have a different purpose than models to begin with. So the short asnwer is no.
Upvotes: 1
Reputation: 1075
No, don't do that! That defeats the whole object of MVC. Leave all functions in the model public unless they are only to be used by that model or related models. In which case they can be private/protected respectively.
If you extend your model to the controller then the controller turns into a model.
Upvotes: 3