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 :: php get epoch timestamp of date 
Php :: Maintenace Mode Up using cron 
Php :: chart trong laravel 
Php :: laravel collection pull 
Php :: laravel firstorcreate with multiple parameters 
Php :: how to pass javascript variable to php 
Php :: PHP strspn — Finds the length of the initial segment of a string consisting entirely of characters contained within a given mask 
Php :: laravel get cookie value 
Php :: phpdoc array type 
Php :: PHP SimpleXML - Get Node Values 
Php :: laravel required_if fileld has value 
Php :: upgrade phpopensuse 
Php :: how to auto increment id after delete value in php mysql 
Php :: Remove WordPress Login error hints 
Php :: Hide products only show assigned products to certain user roles in WooCommerce 
Php :: laravel child relation get max value 
Php :: laravel-5-on-shared-hosting-wrong-public-path 
Php :: if condition in laravel blade in select option 
Php :: update request php-salesforce-rest-api 
Php :: Laravel Mix npm run production error 
Php :: php tipi array 
Php :: swift mailer 530 Must issue a STARTTLS command first. 
Php :: error php 
Php :: must return a relationship instance laravel 
Php :: remove exact characters from string using php 
Php :: How to protect your website from DDos Attack? 
Php :: php hash list 
Java :: androidx recyclerview dependency 
Java :: spring boot maven run with profile 
Java :: how to check if a string contains only alphabets and numbers in java 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =