public function show($id) { $song = Song::findOrFail($id); $is_love = false; if (Auth::user()) { $love = ['song_collection_id' => $song->song_id, 'love_source' => 0, 'love_user' => Auth::user()->id]; $row = Love::where($love)->first(); if ($row) { $is_love = true; } } return view('song/show', compact('song', 'is_love')); }
public function love($source, $collection_id) { if (Auth::user()) { $love = ['song_collection_id' => $collection_id, 'love_source' => $source, 'love_user' => Auth::user()->id]; $row = Love::where($love)->first(); if ($row) { $row->delete(); return 1; } else { Love::create($love); return 2; } } return 0; }
/** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { $music = Music::orderBy('music_id', 'desc')->first(); $love = ['song_collection_id' => $music->music_id, 'love_source' => 1]; $loves = Love::where($love)->count(); $is_love = false; if (Auth::user()) { $love['love_user'] = Auth::user()->id; $row = Love::where($love)->first(); if ($row) { $is_love = true; } } $previous = Music::where('music_id', '<', $music->music_id)->max('music_id'); $next = Music::where('music_id', '>', $music->music_id)->min('music_id'); return view('music/show', compact('music', 'loves', 'is_love', 'previous', 'next')); }