= 1073741824) { $bytes = number_format($bytes / 1073741824, 2).' GB'; } elseif ($bytes >= 1048576) { $bytes = number_format($bytes / 1048576, 2).' MB'; } elseif ($bytes >= 1024) { $bytes = number_format($bytes / 1024, 2).' KB'; } elseif ($bytes > 1) { $bytes = $bytes.' bytes'; } elseif ($bytes == 1) { $bytes = $bytes.' byte'; } else { $bytes = '0 bytes'; } return $bytes; } /** * Get user photo image tag. * * @param \App\User $user * @param array $attributes * @return \Illuminate\Support\HtmlString */ function userPhoto(User $user, $attributes = []) { return Html::image( userPhotoPath($user->photo_path, $user->gender_id), null, $attributes ); } /** * Get user photo by path. Return default gender icon by default. * * @param string $photoPath * @param int $genderId * @return string */ function userPhotoPath($photoPath, $genderId) { if (is_file(public_path('storage/'.$photoPath))) { return asset('storage/'.$photoPath); } return asset('images/icon_user_'.$genderId.'.png'); } /** * Create family tree for specified user. * * @param User $user * @return string */ function createFamilyTree(User $user) { $linkToRoute = link_to_route('users.tree', $user->name, [$user->id], ['title' => $user->name.' ('.$user->gender.')']); $header = <<$linkToRoute HTML; $createFamilyTree = function ($user, User $parent = null, $level = 1) use (&$createFamilyTree) { $linkToRoute = link_to_route('users.tree', $user->name, [$user->id], ['title' => $user->name.' ('.$user->gender.')']); $basicHeader = <<$linkToRoute HTML; $soleString = ""; if ($parent && $parent->childs->count() === 1) { $soleString = "sole"; } $header = << $basicHeader HTML; $childContainer = ""; if ($user->childs->count() !== 0 ) { $nextLevel = $level + 1; $childContainer = "