@if ($showAllCheckins) Check-ins @else Recent Check-ins @endif

    @if($showAllCheckins) @php $checkinsList = array_reverse($trip->checkins) @endphp @else @php $checkinsList = array_slice(array_reverse($trip->checkins), 0, 10) @endphp @endif @foreach($checkinsList as $checkin)
  1. {{ $checkin->title ?? "[No title]" }}

    {!! render_date_difference($checkin->date) !!}

    {{ $checkin->note ?? "[No note]" }} @if($checkin->image_url) @endif
  2. @endforeach
@if (!$showAllCheckins)

Show all checkins

@endif
@php function render_date_difference ($start_time) { $minute = 60; $hour = $minute * 60; $day = $hour * 24; $week = $day * 7; $month = $week * 4; $year = $month * 12; $start_time_dt = new DateTime($start_time); $now = new DateTime(); $trip_start_difference = intval(($now->getTimestamp() - $start_time_dt->getTimestamp())); $start_tag = ''; $end_tag = ''; $unit = null; $div = 1; if ($trip_start_difference < $minute) { $unit = 'second'; } else if ($trip_start_difference < $hour) { $div = $minute; $unit = 'minute'; } else if ($trip_start_difference < $day) { $div = $hour; $unit = 'hour'; } else if ($trip_start_difference < $week) { $div = $day; $unit = 'day'; } else if ($trip_start_difference < $month) { $div = $week; $unit = 'week'; } else if ($trip_start_difference < $year) { $div = $month; $unit = 'month'; } else { $div = $year; $unit = 'year'; } return "{$start_tag}" . ( floor ( $trip_start_difference / $div ) ) . " {$unit}" . ( ( floor ( $trip_start_difference / $div ) > 1 ) ? 's' : '' ) . " ago{$end_tag}"; } @endphp