image common function in laravel model

   <img src="{!! $getrecord->getImage() !!}" alt="{!! $getrecord->name !!}">

  

 

public function getImage() {
         if(!empty($this->profile_pic) && file_exists('upload/profile/'.$this->profile_pic)) {
            return url('upload/profile/'.$this->profile_pic);
         }
         else {
            return url('upload/profile/iconprofile.png');
         }
    }

 

 

 

   public function getName() {
        $name = '';
        $name .= ucfirst($this->name);
        if(!empty($this->last_name))
        {
            $name .= ' '.ucfirst($this->last_name[0]);      
        }    
        return $name;
    }
 

Comments

Popular posts from this blog

codeigniter

laravel password print