public function store2(Request $request) { $this->validate($request, ['live_id' => 'required', 'content' => 'required_with:title', 'title' => 'max:255']); $favorite = new Livefav(); $favorite->user_id = $request->user()->id; $favorite->live_id = $request->input('live_id'); $favorite->created_at = new Carbon(); if ($request->has('content')) { $review = new Liverev(); $review->user_id = $favorite->user_id; $review->live_id = $request->input('live_id'); $review->title = $request->input('title'); $review->content = $request->input('content'); if ($review->save()) { DB::table('lives')->where('id', $review->live_id)->increment('reviews'); } else { return redirect()->back()->withInput()->withErrors('添加失败'); } } if ($favorite->save()) { DB::table('lives')->where('id', $favorite->live_id)->increment('favorites'); return redirect()->route('live.show', [$favorite->live_id]); } else { return redirect()->back()->withInput()->withErrors('评论添加成功,收藏添加失败!'); } }
public function store(Request $request) { $this->validate($request, ['live_id' => 'required', 'content' => 'required', 'title' => 'max:255']); $review = new Liverev(); $review->live_id = $request->input('live_id'); $review->user_id = $request->user()->id; $review->title = $request->input('title'); $review->content = $request->input('content'); if ($review->save()) { DB::table('lives')->where('id', $review->live_id)->increment('reviews'); return redirect()->route('liverev.show', [$review]); } else { return redirect()->back()->withInput()->withErrors('添加失败'); } }