Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. $songs = DB::table('songs')
  2. ->join('song_user', 'songs.id', '=', 'song_user.song_id')
  3. ->where('song_user.user_id', '=', $user->id)
  4. ->orderBy("song_user.play_count", "desc")
  5. ->get();
  6.  
  7. $songs = Song::
  8. with(array("song_user" => function($query) use ($user) {
  9. $query->where("user_id", "=", $user->id)->orderBy("play_count", "desc");
  10. }))
  11.  
  12. public function songs() {
  13. return $this
  14. ->belongsToMany('Song')
  15. ->withPivot('play_count')
  16. ->orderBy('pivot_play_count', 'desc');
  17. }
  18.  
  19. Jingle Bells: 5
  20. Mary had a little lamb: 10
  21. Soft Kitty: 20
  22. The Catalyst: 100
  23.  
  24. The Catalyst: 100
  25. Soft Kitty: 20
  26. Mary had a little lamb: 10
  27. Jingle Bells: 5
  28.  
  29. $songs = Song->join('song_user', 'songs.id', '=', 'song_user.song_id')
  30. ->where('song_user.user_id', '=', $user->id)
  31. ->orderBy("song_user.play_count", "desc")
  32. ->get();
  33.  
  34. $article->tags()->order_by( 'order')->get();
  35.  
  36. return $this->belongsToMany('AppPost')->withTimestamps()->orderByDesc('posts.created_at');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement