Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. | USERS | JOBS | BIDS
  2. | id | id | id
  3. | username | user_id | user_id
  4. | password | title | job_id
  5. | | | bid_amount
  6.  
  7. public function bids()
  8. {
  9. return $this->hasMany('AppRocketCandyReposBidsBid');
  10. }
  11.  
  12. public function user()
  13. {
  14. return $this->belongsTo('AppRocketCandyReposUsersUser');
  15. }
  16.  
  17. public function jobs()
  18. {
  19. return $this->hasMany('AppRocketCandyReposJobsJob');
  20. }
  21.  
  22. public function bids()
  23. {
  24. return $this->hasMany('AppRocketCandyReposBidsBid');
  25. }
  26.  
  27. public function jobs()
  28. {
  29. return $this->belongsTo('AppRocketCandyReposJobsJob');
  30. }
  31.  
  32. public function users()
  33. {
  34. return $this->belongsTo('AppRocketCandyReposUsersUser');
  35. }
  36.  
  37. public function getUsersJobs($userId)
  38. {
  39. // Get the jobs that the user posted
  40. $postedJobs = Job::where('user_id', $userId)
  41. ->lists('id')
  42. ->toArray();
  43.  
  44. // Get the jobs that the user is bidding on
  45. $biddedJobs = Job::with('bids')
  46. ->whereHas('bids', function ($q) use ($userId) {
  47. $q->where('user_id', $userId);
  48. })->lists('id')
  49. ->toArray();
  50.  
  51. $jobIds = array_merge($postedJobs, $biddedJobs);
  52.  
  53. // Return the jobs that a user has posted and is bidding on
  54. return Job::whereIn('id', $jobIds)
  55. ->OrderBy('updated_at', 'DESC')
  56. ->get();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement