douruyun8153 2017-01-01 17:04
浏览 51

使用事件插入laravel中的数据库

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效