public function getUserAttribute()
    {
        if($this->createdByUserID) {

            // search in cache
            $user = User::where('userID', $this->createdByUserID)->first();

            // search in database
            if (!$user) {
                $user = $this->getRelationValue('user');
            }
            return $user;
        }
        return null;
    }
public function getUserAttribute()
    {
        if($this->createdByUserID) {

            // search in cache
            $user = User::where('userID', $this->createdByUserID)->first();

            // search in database
            if (!$user) {
                $user = $this->getRelationValue('user');
            }
            return $user;
        }
        return null;
    }
public function getUserAttribute ( ) { if ( $ this -> createdByUserID ) { // search in cache $ user = User :: where ( 'userID' , $ this -> createdByUserID ) -> first ( ) ; // search in database if ( ! $ user ) { $ user = $ this -> getRelationValue ( 'user' ) ; } return $ user ; } return null ; }
Get user that belongs to a post.

@return mixed|null
@throws \Exception
Get user that belongs to a post .