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

Asked

Viewed 51 times

1

I have an administrative panel with several areas your item listings from each own table. 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' receiving 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.

  • I think it’s best to create a "list" for each one, and keep the rules properly separated. It will generate more code, but everything will be more "readable". More will remain to make modifications, or isolate and solve future problems.

  • Kelvym, for your trouble there I would suggest using a scaffold Enerator, huh.

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 listings. However, there may be differences of functionalities accompanied in the listings. A search filter for example that you can have in one and not have in another. If you just do a controller and a method you don’t separate the responsibilities.

If you have a table of departamentos and another of niveis of users. It would have a Departmentocontroller with a method for listing departments and a Nivelcontroller with a method for listing levels. Finally a model Department and another Level.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.