Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

paypip's avatar
Level 1

How to get current job, total years and company count from user experience?

Hi,

I try to do 3 things with $user->experiences:

  • want get current job (where user still work, so end_date is null)
  • want count how many years from first job to now
  • want count how many different company user work before

thanks! 🙏

0 likes
4 replies
paypip's avatar
Level 1

@tisuchi

tisuchi's avatar
tisuchi
Best Answer
Level 70

@paypip You can try this:


$currentRole = $user->experiences->whereNull('end_date')->first();
$yearsOfExperience = ceil(abs(now()->diffInYears($user->experiences->min('start_date'))));
$companiesCount = $user->experiences->pluck('company')->unique()->count();

I assume that $user->experiences relationship has been set correctly.

1 like

Please or to participate in this conversation.