Obraz istnieje w Laravel
if(File::exists(public_path('images/1461177230.jpg'))){ dd('File is exists.');}else{ dd('File is not exists.');}
Tyagi420
if(File::exists(public_path('images/1461177230.jpg'))){ dd('File is exists.');}else{ dd('File is not exists.');}
if(file_exists(public_path('images/1461177230.jpg'))){ dd('File is exists.');}else{ dd('File is not exists.');}
//Function will check if image exist then returned the passed image otherwise return the default image
function checkImage($path = '', $placeholder = '')
{
if (empty($placeholder)) {
$placeholder = 'placeholder.png';
}
if (!empty($path)) {
$url = explode('storage', $path);
$url = public_path() . '/storage' . $url[1];
$isFile = explode('.', $url);
if (file_exists($url) && count($isFile) > 1)
return $path;
else
return asset('img/' . $placeholder);
} else {
return asset('img/' . $placeholder);
}
}