Witam serdecznie

Mam taki kod (Laravel 7):

Controller:
  1.  
  2. class PageController extends Controller
  3. {
  4.  
  5. protected $repository;
  6.  
  7. public function __construct(PageRepository $repository)
  8. {
  9. $this->repository = $repository;
  10. }
  11.  
  12. public function index()
  13. {
  14. return view('cms.page.list');
  15. }
  16.  
  17.  
  18. public function create()
  19. {
  20. return view('cms.page.view');
  21. }
  22.  
  23.  
  24. public function store(PageCreateRequest $request)
  25. {
  26. $data = [
  27. 'title' => $request->input('title'),
  28. 'description' => $request->input('description') questionmark.gif $request->input('title'),
  29. 'keywords' => $request->input('keywords') questionmark.gif $request->input('title'),
  30. 'content' => $request->input('content'),
  31. 'enable' => $request->input('enable') questionmark.gif 0,
  32. ];
  33. $this->repository->create($data);
  34. return redirect()->route('page.index')->with('success', 'Nowy rekord zapisany poprawnie');
  35. }
  36.  
  37.  
  38. public function edit(int $id)
  39. {
  40. return view('cms.page.view', ['page' => $this->repository->getModel($id), 'fileCount' => 5, 'fileFolder' => 'DZ_TEXT_PAGE', 'fileId' => $id]);
  41. }
  42.  
  43.  
  44. public function update(PageUpdateRequest $request, int $id)
  45. {
  46. $data = [
  47. 'title' => $request->input('title'),
  48. 'description' => $request->input('description'),
  49. 'keywords' => $request->input('keywords'),
  50. 'content' => $request->input('content'),
  51. 'enable' => $request->input('enable') questionmark.gif 0,
  52. ];
  53. $this->repository->update($data, $id);
  54. return redirect()->route('page.index')->with('success', 'Zmiany zapisane pomyślnie');
  55. }
  56.  
  57.  
  58. public function destroy(Request $request, int $id, DropZoneService $dropZoneService)
  59. {
  60. $fileList = $dropZoneService->getFilesList($id, 'products');
  61. foreach ($fileList as $key => $value) {
  62. $dropZoneService->removeDropZoneFile($id, 'products', $value->id);
  63. }
  64. $this->repository->delete($id);
  65. return redirect()->route('page.index')->with('success', 'Rekord usunięty poprawnie');
  66. }
  67.  
  68. public function dataTable(Request $request)
  69. {
  70. if ($request->ajax()) {
  71. return Datatables::of($this->repository->getAll())
  72. ->addIndexColumn()
  73. ->editColumn('enable', function ($row) {
  74. if ($row->enable == 1)
  75. return '<span class="btn btn-block btn-info btn-sm text-white d-sm-inline mr-md-1 mr-sm-1 py-sm-2"><i class="far fa-smile-beam pr-lg-1 d-inline-block d-lg-inline"></i><span class="d-none d-xl-inline">Aktywny</span> </span>';
  76. else return '<span class="btn btn-block btn-secondary btn-sm text-white d-sm-inline mr-md-1 mr-sm-1 py-sm-2"> <i class="far fa-frown pr-lg-1 d-inline-block d-lg-inline"></i><span class="d-none d-xl-inline">Nieaktywny</span> </span>';
  77.  
  78. })
  79. ->editColumn('title', function ($row) {
  80. return Str::limit($row->title, 80, '...');
  81. })
  82. ->editColumn('title', function ($row) {
  83. return '<a href="' . route('page.edit', ['id' => $row->id]) . '">' . $row->title . '</a>';
  84. })
  85. ->addColumn('action', function ($row) {
  86. $btn = '<a href="' . route('page.edit', ['id' => $row->id]) . '" class="btn btn-block btn-warning btn-sm text-white d-sm-inline mr-md-1 mr-sm-1 py-sm-2"><i class="far fa-edit pr-lg-1 d-inline-block d-lg-inline"></i></a> ';
  87. $btn .= '<a href="' . route('page.destroy', ['id' => $row->id]) . '" class="btn btn-block btn-danger btn-sm text-white d-sm-inline py-sm-2"><i class="far fa-trash-alt pr-lg-1 d-inline-block d-lg-inline"></i></a> ';
  88.  
  89. return $btn;
  90. })
  91. ->rawColumns(['title', 'action', 'enable'])
  92. ->make(true);
  93. }
  94. }


Page Repository:
  1.  
  2.  
  3. class PageRepository
  4. {
  5.  
  6. public function __construct(Page $model)
  7. {
  8. $this->model = $model;
  9. }
  10.  
  11. /**
  12.   * @param string $slug
  13.   * @return mixed
  14.   */
  15. public function getTextPageFromSlug(string $slug)
  16. {
  17. return $this->model->active()->where('slug', $slug)->first();
  18. }
  19.  
  20. public function getAll()
  21. {
  22. return $this->model->all();
  23. }
  24.  
  25. public function create(array $data)
  26. {
  27. $this->model->create($data);
  28. }
  29.  
  30. public function update(array $data, int $id)
  31. {
  32. $record = $this->model->findOrFail($id);
  33. $record->title = $data['title'];
  34. $record->description = $data['description'];
  35. $record->keywords = $data['keywords'];
  36. $record->content = $data['content'];
  37. $record->enable = $data['enable'] questionmark.gif 0;
  38. $record->save();
  39. }
  40.  
  41. public function delete(int $id)
  42. {
  43. $record = $this->model->findOrFail($id);
  44. $record->delete();
  45. }
  46.  
  47. public function getModel($id)
  48. {
  49. return $this->model->findOrFail($id);
  50. }
  51.  
  52. }
  53.  

(Controller + repositorium). Nie korzystam w projekcie z Repository Pattern: https://bosnadev.com/2015/03/07/using-repos...aign=prettus-l5

Wydzieliłem sobie tylko funkcje związane z bazami danych do osobnego Pliku (Page Repository). Czy takie podejście jest dobre (dobre praktyki programowania)?
Czy lepiej te funkcje z PageRepository przenieść do Modelu?

Czytałem troszkę w internecie, i z tego co widzę to ludzie zalecają PageRepository - a w momencie gdy controller robi się zbyt "duży" to dodatkowo serwisy.

Czy mógłbym prosić o opinie? smile.gif