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 :: woocommerce check if cart is not empty 
Php :: php set array 
Php :: laravel 8 selecet the 2nd to the last record 
Php :: validate executable path vscode 
Php :: truncate table laravel eloquent 
Php :: asset not working in laravel 
Php :: get current year php 
Php :: clear laravel cache 
Php :: how to remove public from url in laravel 
Php :: Displaying all table names in php from MySQL database 
Php :: woocommerce action order complete 
Php :: php convert special characters to unicode 
Php :: limit offset array php 
Php :: guzzlehttp php basic auth 
Php :: php find key in array 
Php :: php inline if null check 
Php :: how to write for loop in laravel blade 
Php :: How to get only year, month and day from timestamp in Laravel 
Php :: how to install dompdf in laravel 
Php :: password hashing in laravel 
Php :: php quit 
Php :: php parse url get path 
Php :: php check if function exists 
Php :: toaster message in laravel 
Php :: PHP str_replace — Replace all occurrences of the search string with the replacement string 
Php :: php post 
Php :: how to get the average in sql in php 
Php :: how to run php file in xampp 
Php :: php clean all output buffers 
Php :: response()-make laravel pdf 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =