login page, in ideal MVC framework, you would have a model called e.g. LoginModel this model would have login method which would contain all the logic of what will happen if the user is trying to login from validations to authentication and security checks.
now you have a controller called LoginController, this controller would get called when the user is on domain.tld/login
It would render the views accordingly and call the logic in the models,
Like:
// if user is logged in redirect to main-page, if not show the view
if (LoginModel::isUserLoggedIn()) {
Redirect::home();
} else {
$data = array('redirect' => Request::get('redirect') ? Request::get('redirect') : NULL);
$this->View->render('login/index', $data);
}
Pls note that in ideal properly implemented MVC controller MUST NOT contain logic
But in Laravel I was just using logic as a method in a controller. So is it best practice to include logic in model instead a controller?
Обсуждают сегодня