Exemple #1
0
 public function store2(Request $request)
 {
     $validator = Validator::make($request->all(), ['drama_id' => 'required', 'episode_id' => 'required', 'content' => 'required_with:title', 'visible' => 'required_with:content', 'type' => 'required|in:0,2,4', 'rating' => 'in:0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5', 'title' => 'max:255']);
     if ($validator->fails()) {
         return response($validator->messages(), 422);
     }
     $epfav = new Epfav();
     $epfav->user_id = $request->user()->id;
     $epfav->episode_id = $request->input('episode_id');
     $epfav->type = $request->input('type');
     if ($epfav->type == 0) {
         $epfav->rating = 0;
     } else {
         $epfav->rating = $request->input('rating');
     }
     if ($epfav->save()) {
         DB::table('users')->where('id', $epfav->user_id)->increment('epfav' . $epfav->type);
         DB::table('episodes')->where('id', $epfav->episode_id)->increment('favorites');
         if ($request->has('content')) {
             $review = new Review();
             $review->user_id = $epfav->user_id;
             $review->drama_id = $request->input('drama_id');
             $review->episode_id = $epfav->episode_id;
             $review->title = $request->input('title');
             $review->content = $request->input('content');
             $review->visible = $request->input('visible');
             if ($review->save()) {
                 DB::table('users')->where('id', $review->user_id)->increment('reviews');
                 DB::table('dramas')->where('id', $review->drama_id)->increment('reviews');
                 DB::table('episodes')->where('id', $review->episode_id)->increment('reviews');
             } else {
                 return response('收藏添加成功,评论添加失败> <', 422);
             }
         }
         return ['result' => 'success'];
     } else {
         return response('添加失败> <', 422);
     }
 }
Exemple #2
0
 public function store2(Request $request)
 {
     $this->validate($request, ['drama_id' => 'required', 'episode_id' => 'required', 'content' => 'required_with:title', 'visible' => 'required_with:content', 'type' => 'required|in:0,2,4', 'rating' => 'in:0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5', 'title' => 'max:255']);
     $epfav = new Epfav();
     $epfav->user_id = $request->user()->id;
     $epfav->episode_id = $request->input('episode_id');
     $epfav->type = $request->input('type');
     if ($epfav->type == 0) {
         $epfav->rating = 0;
     } else {
         $epfav->rating = $request->input('rating');
     }
     if ($epfav->save()) {
         DB::table('users')->where('id', $epfav->user_id)->increment('epfav' . $epfav->type);
         DB::table('episodes')->where('id', $epfav->episode_id)->increment('favorites');
         //评论内容不为空则新建评论
         if ($request->has('content')) {
             $review = new Review();
             $review->user_id = $epfav->user_id;
             $review->drama_id = $request->input('drama_id');
             $review->episode_id = $epfav->episode_id;
             $review->title = $request->input('title');
             $review->content = $request->input('content');
             $review->visible = $request->input('visible');
             if ($review->save()) {
                 DB::table('users')->where('id', $review->user_id)->increment('reviews');
                 DB::table('dramas')->where('id', $review->drama_id)->increment('reviews');
                 DB::table('episodes')->where('id', $review->episode_id)->increment('reviews');
             } else {
                 return redirect()->back()->withInput()->withErrors('收藏添加成功,评论添加失败');
             }
         }
         return redirect()->route('episode.show', [$epfav->episode_id]);
     } else {
         return redirect()->back()->withInput()->withErrors('添加失败!');
     }
 }