VideoController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Http\Controllers\Web;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\VideoRequest;
  5. use App\Models\Video;
  6. use App\Models\VideoCategory;
  7. use App\Services\VideoService;
  8. use Illuminate\Http\Request;
  9. class VideoController extends Controller
  10. {
  11. //
  12. public function index(Request $request, VideoService $service){
  13. $category = VideoCategory::select('id', 'name','is_show','rank')->where('is_show', 1)->where('pid', 0)->orderBy('rank','DESC')->get()->toArray();
  14. $condition['keywords'] = $request->input('keywords', '');
  15. $condition['category_id'] = $request->input('category_id', 0);
  16. // $condition['platform'] = 'psy_center';
  17. $condition['type'] = 3;
  18. $condition['platform'] = 'psy_center';
  19. $video = $service->getList($condition);
  20. // var_dump($video);exit;
  21. // print_r($category);exit;
  22. return view('psycenter.video', ['categories'=>$category, 'video'=>$video,'condition'=>$condition, 'title'=>'视频']);
  23. }
  24. public function store(VideoRequest $request)
  25. {
  26. $category = new Video();
  27. $request->merge(['type' => 3]);
  28. $request->merge(['platform'=>'psy_center']);
  29. if ($request->has('id')){
  30. $category = Video::find($request->input('id'));
  31. $result = $category->fill($request->all());
  32. $res = $result->save();
  33. }else{
  34. $result = $category->fill($request->all());
  35. $res = $result->save();
  36. }
  37. return $res ? $this->success($result) : $this->failed('保存失败');
  38. }
  39. public function show($id)
  40. {
  41. $video = Video::where('id', $id)->firstOrFail();
  42. return $this->success($video);
  43. }
  44. public function destroy($id)
  45. {
  46. Video::where('id', $id)->firstOrFail();
  47. $res = Video::destroy($id);
  48. if($res) {
  49. return $this->success('');
  50. }else {
  51. return $this->failed('删除失败');
  52. }
  53. }
  54. public function delete()
  55. {
  56. $ids = request()->input('ids');
  57. $res = Video::whereIn('id', $ids)->delete();
  58. if($res) {
  59. return $this->success('');
  60. }else {
  61. return $this->failed('删除失败');
  62. }
  63. }
  64. }