Laravel - Creating a request in a controller or model? For large web applications

Quick question, I am learning Laravel 4, as I come from Codeigniter, I noticed that some tutorials on laravel have their own queries in the controller, and some have their own queries in the model.

My question is: where should we write all our queries for best practice? In the controller or model? This applies to large web applications.

Many thanks

+3
source share
1 answer

It’s best to write your queries on a separate level. Therefore, separate from your controller and separately from your model. The best controller practice also depends on the size of your project and your specific demand for maintainability.

, , - . , , :

class UserRepository {

    public function __construct(Illuminate\Database\DatabaseManager $db)
    {
        $this->db = $db;
    }

    public function getLatestUsers($limit = 5) {
        //$this->db->table('users')->
    }

}

, laravel.

+2

All Articles