Answers for "Add custom columns to models"

0

Add custom columns to models

// User model

class User extends Authenticatable
{
    /**
     * Return the full_name by concatinating 
     * the first_name . ' ' . last_name
     *
     * @return String
     */
    function getFullNameAttribute() {
    
        return sprintf('%s %s', $this->first_name, $this->last_name);
    }
}

// Usage

User::first()->full_name;
Posted by: Guest on October-24-2021

Code answers related to "Add custom columns to models"

Browse Popular Code Answers by Language