MVC and Model responsibilities

487 views laravel
1

I have a small Laravel project. In this project I have a few models, but the ones required for my question are User model, a Course model and a Payment model.

A User can subscribe to a Course (only one) and needs to pay a monthly amount for his subscription.

I'm creating a new page that will show different contents depending on the current status of the User. If they failed a payment, I will display ContentA, if all payments are up to date ContentB will be displayed.

Is it correct, from a MVC architecture point of view, to create a function in the User model hasFailedPayments() that will perform all required operations and checks to decide if the User has failed payments? Should this be a responsibility of one of the other layers (Controller/View)?

At the moment I'm making the checks in the Controller but if I need to do the exact same check I will need to duplicate this code.

Thanks in advance!

answered question

1 Answer

7

You are correct, this logic would live in the Model. In most cases most or all of your business logic should live inside your models. The View is there to see the data resulting from the logic. The controllers are there to serve the views with the models and control the overall flow of the project.

posted this

Have an answer?

JD

Please login first before posting an answer.

Ads

Categories