I am trying to find most occurred item in database. I already done this in one way but want to use events for this can any one help me to use events so I can understand about laravel events also the way i done was this insert to database when a link is clicked and selecting the data which occurred more than 2 times my code is like this function inserts when button is clicked and start downloading
public function song_download($url)
{
$download = DB::table('song_details')->select('song_location')->where('song_title',$url)->get();
$path = 'songs/'.$download{0}->song_location.'.mp3';
return response()->download($path);
}
When index page loads to show most popular content, I used a function like this.
public function index()
{
$songs = Song_detail::select()->latest()->get();
$malayalamSongs = Mostpopular::select('song_id')->groupBy('song_id')->havingRaw('COUNT(*) > 3')->get();
return view('pages.index',compact('songs','malayalamSongs'));
}
Please help me to understand whether there is any best method than this using laravels events.