Esempio n. 1
0
 public function store2(Request $request)
 {
     $this->validate($request, ['ft_id' => 'required', 'ftep_id' => 'required', 'content' => 'required_with:title', 'title' => 'max:255']);
     $favorite = new Ftepfav();
     $favorite->user_id = $request->user()->id;
     $favorite->ftep_id = $request->input('ftep_id');
     $favorite->created_at = new Carbon();
     if ($request->has('content')) {
         $review = new Ftrev();
         $review->user_id = $favorite->user_id;
         $review->ft_id = $request->input('ft_id');
         $review->ftep_id = $request->input('ftep_id');
         $review->title = $request->input('title');
         $review->content = $request->input('content');
         if ($review->save()) {
             DB::table('fts')->where('id', $review->ft_id)->increment('reviews');
             DB::table('fteps')->where('id', $review->ftep_id)->increment('reviews');
         } else {
             return redirect()->back()->withInput()->withErrors('添加失败');
         }
     }
     if ($favorite->save()) {
         DB::table('fteps')->where('id', $favorite->ftep_id)->increment('favorites');
         return redirect()->route('ftep.show', [$favorite->ftep_id]);
     } else {
         return redirect()->back()->withInput()->withErrors('评论添加成功,收藏添加失败!');
     }
 }
Esempio n. 2
0
 public function reviews($id)
 {
     $ft = Ft::find($id, ['id', 'title']);
     $reviews = Ftrev::with(['user' => function ($query) {
         $query->select('id', 'name');
     }])->select('id', 'user_id', 'title', 'content', 'created_at')->where('ft_id', $id)->paginate(20);
     return view('ft.reviews', ['ft' => $ft, 'reviews' => $reviews]);
 }
Esempio n. 3
0
 public function zhoubian()
 {
     $newsongs = Song::select('id', 'title', 'alias', 'artist')->orderBy('id', 'desc')->take(15)->get();
     $songrevs = Songrev::with(['user' => function ($query) {
         $query->select('id', 'name');
     }, 'song' => function ($query) {
         $query->select('id', 'title');
     }])->orderBy('id', 'desc')->take(10)->get();
     $hotrevsongs = Songrev::with(['song' => function ($query) {
         $query->select('id', 'title', 'artist');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, song_id'))->groupBy('song_id')->orderBy('review_count', 'desc')->take(15)->get();
     $hotfavsongs = Songfav::with(['song' => function ($query) {
         $query->select('id', 'title', 'artist');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, song_id'))->groupBy('song_id')->orderBy('favorite_count', 'desc')->take(15)->get();
     $newcreatedfteps = Ftep::with(['ft' => function ($query) {
         $query->select('id', 'title', 'host');
     }])->select('id', 'ft_id', 'title', 'release_date')->orderBy('id', 'desc')->take(10)->get();
     $ftrevs = Ftrev::with(['user' => function ($query) {
         $query->select('id', 'name');
     }, 'ft' => function ($query) {
         $query->select('id', 'title');
     }, 'ftep' => function ($query) {
         $query->select('id', 'title');
     }])->orderBy('id', 'desc')->take(10)->get();
     $hotrevfts = Ftrev::with(['ft' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, ft_id'))->groupBy('ft_id')->orderBy('review_count', 'desc')->take(10)->get();
     $hotfavfts = Ftfav::with(['ft' => function ($query) {
         $query->select('id', 'title');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, ft_id'))->groupBy('ft_id')->orderBy('favorite_count', 'desc')->take(10)->get();
     $todaylives = Live::select('id', 'title', 'showtime')->whereRaw('date(showtime) = curdate()')->orderBy('showtime')->get();
     $newlives = Live::select('id', 'title', 'showtime')->orderBy('id', 'desc')->take(15)->get();
     $liverevs = Liverev::with(['user' => function ($query) {
         $query->select('id', 'name');
     }, 'live' => function ($query) {
         $query->select('id', 'title', 'showtime');
     }])->orderBy('id', 'desc')->take(10)->get();
     $hotrevlives = Liverev::with(['live' => function ($query) {
         $query->select('id', 'title', 'showtime');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as review_count, live_id'))->groupBy('live_id')->orderBy('review_count', 'desc')->take(15)->get();
     $hotfavlives = Livefav::with(['live' => function ($query) {
         $query->select('id', 'title', 'showtime');
     }])->where('created_at', '>=', date("Y-m-d H:i:s", strtotime("-30 day")))->select(DB::raw('count(*) as favorite_count, live_id'))->groupBy('live_id')->orderBy('favorite_count', 'desc')->take(15)->get();
     return view('zhoubian', ['newsongs' => $newsongs, 'songrevs' => $songrevs, 'hotrevsongs' => $hotrevsongs, 'hotfavsongs' => $hotfavsongs, 'newcreatedfteps' => $newcreatedfteps, 'ftrevs' => $ftrevs, 'hotrevfts' => $hotrevfts, 'hotfavfts' => $hotfavfts, 'todaylives' => $todaylives, 'newlives' => $newlives, 'liverevs' => $liverevs, 'hotrevlives' => $hotrevlives, 'hotfavlives' => $hotfavlives]);
 }
Esempio n. 4
0
 public function destroy(Request $request, $id)
 {
     $review = Ftrev::find($id);
     if ($review->user_id == $request->user()->id) {
         if ($review->delete()) {
             DB::table('fts')->where('id', $review->ft_id)->decrement('reviews');
             if ($review->ftep_id) {
                 DB::table('fteps')->where('id', $review->ftep_id)->decrement('reviews');
             }
         }
     }
     return redirect()->back();
 }
Esempio n. 5
0
 public function ftrevs($id)
 {
     $reviews = Ftrev::with(['ft' => function ($query) {
         $query->select('id', 'title');
     }, 'ftep' => function ($query) {
         $query->select('id', 'title');
     }])->select('id', 'ft_id', 'ftep_id', 'title', 'content', 'created_at')->where('user_id', $id)->paginate(20);
     return view('user.ftrevs', ['user' => User::find($id, ['id', 'name']), 'reviews' => $reviews]);
 }