public function scopeLatestLog($query, $type) { return $query->where('case_type', $type)->orderBy('id', 'DESC')->first()->created_at; }