Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | USERS | JOBS | BIDS
- | id | id | id
- | username | user_id | user_id
- | password | title | job_id
- | | | bid_amount
- public function bids()
- {
- return $this->hasMany('AppRocketCandyReposBidsBid');
- }
- public function user()
- {
- return $this->belongsTo('AppRocketCandyReposUsersUser');
- }
- public function jobs()
- {
- return $this->hasMany('AppRocketCandyReposJobsJob');
- }
- public function bids()
- {
- return $this->hasMany('AppRocketCandyReposBidsBid');
- }
- public function jobs()
- {
- return $this->belongsTo('AppRocketCandyReposJobsJob');
- }
- public function users()
- {
- return $this->belongsTo('AppRocketCandyReposUsersUser');
- }
- public function getUsersJobs($userId)
- {
- // Get the jobs that the user posted
- $postedJobs = Job::where('user_id', $userId)
- ->lists('id')
- ->toArray();
- // Get the jobs that the user is bidding on
- $biddedJobs = Job::with('bids')
- ->whereHas('bids', function ($q) use ($userId) {
- $q->where('user_id', $userId);
- })->lists('id')
- ->toArray();
- $jobIds = array_merge($postedJobs, $biddedJobs);
- // Return the jobs that a user has posted and is bidding on
- return Job::whereIn('id', $jobIds)
- ->OrderBy('updated_at', 'DESC')
- ->get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement