FormDataController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Models\FormData;
  4. use Illuminate\Http\Request;
  5. class FormDataController extends Controller
  6. {
  7. protected $redirect_index = '/admin/FormData/index';
  8. protected $view_path = 'admin.form-data.';
  9. protected $pre_uri = '/admin/FormData/';
  10. protected $model_name = '表单数据';
  11. protected $model;
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->model = new FormData();
  16. }
  17. public function index(Request $request)
  18. {
  19. $list = $this->model->where('id', '>', 0)->orderBy('created_at', 'desc');
  20. if(!empty($request->input('keyword')) && !empty(trim($request->input('keyword')))) {
  21. $keyword = '%' . trim($request->input('keyword')) . '%';
  22. $list = $list->where('name', 'like', $keyword);
  23. }
  24. $list = $list->paginate()->withPath($this->getPaginateUrl());
  25. list($pre_uri, $model_name) = array($this->pre_uri, $this->model_name);
  26. return view($this->view_path . 'index', compact('list', 'pre_uri', 'model_name'));
  27. }
  28. public function show(Request $request)
  29. {
  30. if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) {
  31. return $this->showWarning('参数错误');
  32. }
  33. list($pre_uri, $model_name) = array($this->pre_uri, $this->model_name);
  34. return view($this->view_path . 'show', compact('list', 'pre_uri', 'model_name'));
  35. }
  36. public function delete(Request $request)
  37. {
  38. if(!$request->isMethod('POST')) {
  39. return $this->showWarning('访问错误');
  40. }
  41. if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) {
  42. return $this->showWarning('访问错误');
  43. }
  44. $res = $item->delete();
  45. if(!$res) {
  46. return $this->showWarning('数据库删除失败');
  47. }
  48. return $this->showMessage('操作成功');
  49. }
  50. }