0
votes

I'm creating a Laravel app and I have controllers with the CRUD methods, but I need to show reports and I'm not sure if I have to create a controller called 'Reports' or I have to put each report function inside the controller:

  1. First Option:

    • Controllers/ProductController.php
      • Functions (Create, Read, Edit, Update, Delete)
    • Controllers/CategoryController.php
      • Functions (Create, Read, Edit, Update, Delete)
    • Controllers/ReportController.php
      • Functions (TopProducts, TopCategories)
  2. Second Option:

    • Controllers/ProductController.php
      • Functions (Create, Read, Edit, Update, Delete, TopProducts)
    • Controllers/CategoryController.php
      • Functions (Create, Read, Edit, Update, Delete, TopCategories)

I hope you can tell me a which is the best option or your own alternative. Thanks.

1
any way is fine.Sanzeeb Aryal
You may organize your controllers with naming as Controllers/ProductReportController.php, Controllers/CategoryReportController.php etc.Mahbub
Thanks, I want to have a controller standard because our project has more than 50 tables and we're three developers.Developer933

1 Answers

0
votes

I think you should do the first option because your code will be clearer and more separated.

This way, if you want to create more reports from different tables, you will have everything in one controller.

I would advise against option 1 if you are using queries that are already defined in the other controllers, following DRY principles.