Laravel - Do I do an action @list for each Controller or a Controller 'listController' receiving parameters?

1

I have an administrative panel with several areas of your item listings for each table itself. What's best to do:

A action 'list' for each Controller responsible for each area:

class aController extends Controller{
    public function list(){
    }
}
class bController extends Controller{
    public function list(){
    }
}
class cController extends Controller{
    public function list(){
    }
}

Or make a Controller 'ListController' by getting parameters:

class ListController extends Controller{
    public function index($table){
    }
}

The last case seems to solve the problem of code repetitions, but I do not know if it will bring problems in the future.

    
asked by anonymous 25.04.2016 / 22:11

1 answer

1

To avoid future problems and follow the concept of object orientation, I believe that separating the responsibilities of each thing is the best option. We know that several things have a listing. However, there may be differences in features listed in the listings. A search filter for example that you can have in one and not have in another. If you only do one controller and one method you do not separate responsibilities.

If you have a table of departamentos and another table of niveis of users. It would have a DepartmentController with a method for listing departments, and a LevelController also has a method for listing levels. Finally a model Department and other Level.

    
18.05.2016 / 16:13