teete

4 months ago

alexis-riot

te

Code

use Carbon\Carbon;

$project = Project::find(1);
$test = $project->users->sum(function ($user) {
  
  $start = new Carbon($user->pivot->date_from);
  $end = new Carbon($user->pivot->date_to);

  return $start->diffInHoursFiltered(function (Carbon $date) {
    return ($date->hour <= 18 && $date->hour >= 8);
  }, $end);
});

Output

[!] Aliasing 'Project' to 'App\Models\Project' for this Tinker session.
=> 34
New course: Desktop apps with Electron