<?php namespace Riari\Forum\Models\Traits;

trait HasAuthor
{
    /**
     * Relationship: Author.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function author()
    {
        return $this->belongsTo(config('forum.integration.user_model'));
    }

    /**
     * Attribute: Author name.
     *
     * @return mixed
     */
    public function getAuthorNameAttribute()
    {
        $attribute = config('forum.integration.user_name');

        if (!is_null($this->author)) {
            return $this->author->$attribute;
        }

        return null;
    }
}

<?php namespace Riari\Forum\Models\Traits;

trait HasAuthor
{
    /**
     * Relationship: Author.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function author()
    {
        return $this->belongsTo(config('forum.integration.user_model'), 'author_id');
    }

    /**
     * Attribute: Author name.
     *
     * @return mixed
     */
    public function getAuthorNameAttribute()
    {
        $attribute = config('forum.integration.user_name');

        if (!is_null($this->author)) {
            return $this->author->$attribute;
        }

        return null;
    }
}

Set the `foreign_key` attribute on the author belongsTo method
Set the `foreign_key` attribute on the author belongsTo method

When the user model has a custom primary key (e.g `user_id` instead of `id`) Laravel will attempt to guess the foreign key and local key on a `belongsTo` relationship. However if guesses incorrectly.

In the case where the foreign key is `user_id` Laravel 5.4 will interpret the foreign key as `author_user_id`. Manually setting the foregin key to `author_id` fixes this.