VideoCategoryController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Http\Controllers\Web;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\CategoryRequest;
  5. use App\Models\Video;
  6. use App\Models\VideoCategory;
  7. use Illuminate\Http\Request;
  8. class VideoCategoryController extends Controller
  9. {
  10. /**
  11. * Display a listing of the resource.
  12. *
  13. * @return \Illuminate\Http\Response
  14. */
  15. public function index()
  16. {
  17. //
  18. }
  19. /**
  20. * Store a newly created resource in storage.
  21. *
  22. * @param \Illuminate\Http\Request $request
  23. * @return \Illuminate\Http\Response
  24. */
  25. public function store(CategoryRequest $request)
  26. {
  27. //
  28. $request->merge(['pid'=>0]);
  29. $request->merge(['is_show'=>1]);
  30. $category = new VideoCategory();
  31. if ($request->has('id')){
  32. $category = VideoCategory::find($request->input('id'));
  33. $result = $category->fill($request->all());
  34. $res = $result->save();
  35. }else{
  36. $result = $category->fill($request->all());
  37. $res = $result->save();
  38. }
  39. return $res ? $this->success($result) : $this->failed('保存失败');
  40. }
  41. /**
  42. * Display the specified resource.
  43. *
  44. * @param int $id
  45. * @return \Illuminate\Http\Response
  46. */
  47. public function show($id)
  48. {
  49. //
  50. }
  51. /**
  52. * Update the specified resource in storage.
  53. *
  54. * @param \Illuminate\Http\Request $request
  55. * @param int $id
  56. * @return \Illuminate\Http\Response
  57. */
  58. public function update(Request $request, $id)
  59. {
  60. //
  61. }
  62. /**
  63. * Remove the specified resource from storage.
  64. *
  65. * @param int $id
  66. * @return \Illuminate\Http\Response
  67. */
  68. public function destroy($id)
  69. {
  70. //
  71. VideoCategory::where('id', $id)->firstOrFail();
  72. $result = Video::where('first_id', $id)->where('deleted_at', null)->where('platform', 'psy_center')->first();
  73. if($result) {
  74. return $this->failed('该分类下有视频,请先删除视频');
  75. }
  76. $res = VideoCategory::destroy($id);
  77. if($res) {
  78. return $this->success('');
  79. }else {
  80. return $this->failed('删除失败');
  81. }
  82. }
  83. }