private function checkType($query, $type)
{
if (is_numeric($type)) {
return $query->where('type_id', $type)->latest();
} else {
$type = strtolower($type);
return $query->whereHas('type', function ($query) use($type) {
$query->where('name', ucfirst($type));
})->latest();
}
}