Search
 
SCRIPT & CODE EXAMPLE
 

PHP

check image exist or not in laravel

// 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="">
Comment

image exists in laravel

if(File::exists(public_path('images/1461177230.jpg'))){    dd('File is exists.');}else{    dd('File is not exists.');}
Comment

image exists in laravel

if(file_exists(public_path('images/1461177230.jpg'))){    dd('File is exists.');}else{    dd('File is not exists.');}
Comment

Laravel function to check if image exist or not

//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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: displaying laravel error in below input field 
Php :: php var dump die 
Php :: php format date 
Php :: php header location to same page 
Php :: check if value is not null in db laravel 
Php :: php shorthand if isset 
Php :: how convert big text to array that text have br in laravel 
Php :: how to remove jstream package 
Php :: php transform associative array to array 
Php :: php artisan optimize command 
Php :: object of class symfonycomponentformformview could not be converted to string 
Php :: php remove space before and after string 
Php :: how get just one parameter of all objects in one array in laravel 
Php :: subtract some days php 
Php :: NUMBER ONLY IN PHP 
Php :: firebase jwt php verify 
Php :: webuzo set upload limit 
Php :: remove get parameters from url php 
Php :: change php version in ubuntu 
Php :: stream_set_blocking 
Php :: how to remove image from public storage in laravel 
Php :: wpml display language switcher 
Php :: php get file type from url 
Php :: symfony convert entity to array 
Php :: composer deploy production 
Php :: composer create-project laravel/laravel --prefer-dist laravel-bootstrap 
Php :: php.ini location mac 
Php :: translate youtube link into iframe in laravel 
Php :: convert number to 2 decimal places in php 
Php :: current user laravel 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =