C
C
copal2015-12-22 14:37:16
Laravel
copal, 2015-12-22 14:37:16

How to change the model in laravel5 correctly?

How to correctly make the interaction of the route, controller and model for adding a friend?
More details in the code..

class User
{
    public function insertFrien(/** что тут должно быть? */)
    {
        // то что происходит здесь мне пока не интересно
    }
}

// Должен ли быть только один UserController 
// или же должен быть и UserController и UserFriendController?


// Пока пойду по второму пути -

class UserFriendController
{
    public function insert(/** что тут должно быть? */)
    {
        // и что происходит здесь?
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-12-22
@copal

all the controller has to do is ask the model (this is not an active record model, but just some piece of the application that sticks out in the controller) to change the state or do something.
That is, the controller pulls the service, the service works with data and persists changes ... and that's it.
Controllers should be dumb, should not contain logic. It's just a mediator between the application and the UI. Thick controllers lead to code duplication and higher support costs. But for simple projects, in principle, the norms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question