get the registrations of a user in conferences that didnt finished

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



get the registrations of a user in conferences that didnt finished



I have this code to get registration of a users in conferences that have the status incomplete (I).


$IncRegistrations = $user->registrations()->where('status', 'I')->count();



But do you know how to get the registrations of a user in conferences that have the status incomplete but only for the conferences that have the column 'end_date' smaller than now(), that is, conferences that did not finish already?




2 Answers
2



You can use whereDate


whereDate


$IncRegistrations = $user->registrations()
->where('status', 'I')->whereDate('end_date', '<', Carbon::now())->count();



EDIT After Comments use whereHas


whereHas


$IncRegistrations = $user->registrations()
->where('status', 'I')
->whereHas('conference', function($query)
$query->whereDate('end_date', '<', Carbon::now());
)->count();





Thanks, but like that shows "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'end_date' in 'where clause' (SQL: select count(*) as aggregate from registrations where registrations.user_that_did_registration = 1 and registrations.user_that_did_registration is not null and status = I and date(end_date) < 2018-08-11 16:10:53)". The end_date column is from conferences table not registrations table.
– user10178413
Aug 11 at 16:11



registrations


registrations


user_that_did_registration


registrations


user_that_did_registration


status


end_date





what is the relation between registrations and conference ?
– rkj
Aug 11 at 16:54


registrations


conference





Registration model "public function conference() return $this->belongsTo('AppConference'); ".
– user10178413
Aug 11 at 18:48





Conference model " public function registrations() return $this->hasMany('AppRegistration', 'conference_id'); ".
– user10178413
Aug 11 at 18:49





updated answer check it
– rkj
Aug 12 at 5:22



You can use the following code:


$IncRegistrations = $user->registrations()->where('status', 'I')
->where(DB::RAW('DATE(end_date)'), '<', DB::RAW('DATE(NOW())'))->count();





Thanks, but it appear ""SQLSTATE[42S22]: Column not found: 1054 Unknown column 'end_date' in 'where clause' (SQL: select count(*) as aggregate from registrations where registrations.user_that_did_registration = 1 and registrations.user_that_did_registration is not null and status = I and DATE(end_date) < DATE(NOW())) ◀" ".
– user10178413
Aug 11 at 18:50


registrations


registrations


user_that_did_registration


registrations


user_that_did_registration


status






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard