Orl 短網址,供三星、福斯使用

TigerManagementController.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Http\Controllers\Backend\ZooManagement;
  3. use Illuminate\Http\Request;
  4. use App\Http\Services\Backend\ZooManagement\TigerManagementService;
  5. use App\Http\Controllers\Controller;
  6. class TigerManagementController extends Controller
  7. {
  8. // 相關私有服務層調用器宣告
  9. private $tigerManagementSv;
  10. public function __construct()
  11. {
  12. // 建構服務層調用器
  13. $this->tigerManagementSv = new TigerManagementService();
  14. }
  15. /**
  16. * 列表頁
  17. * 本端點非 API,於 controller 取列表值後,存於變量渲染到 view
  18. * 排序、分頁均未實現
  19. * @return array: 返回渲染頁
  20. */
  21. public function index()
  22. {
  23. // 取得參數與驗證
  24. // 服務層取得資料(以及實現各種業務上的邏輯)
  25. $tigers = $this->tigerManagementSv->getTigers();
  26. // 渲染
  27. return view('admin.ZooManagement.TigerManagement', [
  28. 'operdata' => $tigers,
  29. ]);
  30. }
  31. /**
  32. * 新增老虎頁面
  33. * 本端點非 API,直接到 view
  34. * @return array: 返回渲染頁
  35. */
  36. public function create()
  37. {
  38. // 渲染
  39. return view('admin.ZooManagement.TigerManagementEdit', [
  40. 'operdata' => "",
  41. ]);
  42. }
  43. /**
  44. * 編輯老虎頁面
  45. * 本端點非 API,依照變量取得資料後,渲染到 view
  46. *
  47. * @param integer $id : 老虎的自增量
  48. *
  49. * @return array: 返回渲染頁
  50. */
  51. public function edit($id)
  52. {
  53. // 取得參數與驗證
  54. // 服務層取得資料(以及實現各種業務上的邏輯)
  55. $tiger = $this->tigerManagementSv->getTigerById($id);
  56. // 渲染
  57. return view('admin.ZooManagement.TigerManagementEdit', [
  58. 'operdata' => $tiger,
  59. ]);
  60. }
  61. /**
  62. * 新增或編輯老虎的端點
  63. * 本端點非 API,依照參數新增或修改資料後,跳轉到既有的 view
  64. *
  65. * @param Request $request : 整包參數
  66. *
  67. * @return array: 返回跳轉渲染頁的資訊
  68. */
  69. public function store(Request $request)
  70. {
  71. // 取得參數與驗證
  72. $mode = $request->mode;
  73. $id = ($request->mode == 'insert') ? '' : $request->id;
  74. $tigerName = $request->tigerName;
  75. // 服務層設置(以及實現各種業務上的邏輯)
  76. if ($mode == "insert") {
  77. // 新增模式
  78. $this->tigerManagementSv->insertTiger($tigerName);
  79. } else {
  80. // 編輯模式
  81. $this->tigerManagementSv->modifyTiger($id, $tigerName);
  82. }
  83. // 跳轉
  84. return redirect('/backend/zooManagement/tigerManagement');
  85. }
  86. /**
  87. * 刪除老虎的端點
  88. * 本端點非 API,依照參數刪除資料後,跳轉到既有的 view
  89. *
  90. * @param integer $id : 老虎的自增量
  91. *
  92. * @return array: 返回跳轉渲染頁的資訊
  93. */
  94. public function delete($id)
  95. {
  96. // 取得參數與驗證
  97. // 服務層取得資料(以及實現各種業務上的邏輯)
  98. $this->tigerManagementSv->deleteTigerById($id);
  99. // 跳轉
  100. return Redirect::back();
  101. }
  102. }