// User Model
public function photo()
{
if (file_exists( public_path() . '/images/photos/account/' . $this->account_id . '.png')) {
return '/images/photos/account/' . $this->account_id .'.png';
} else {
return '/images/photos/account/default.png';
}
}
// Blade Template
<img src="{!! Auth::user()->photo() !!}" alt="">
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);
}
}