Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

OzzDev's avatar

message: "Call to undefined method App\\Models\\Newsletter::title_color_id()"

I'm having this error:

message: "Call to undefined method App\Models\Newsletter::title_color_id()"

And I'm not understanding how to properly solve it.

I have a newsletter table with this structure:

newsletter table:
id, title, background_color_id, description

The Newsletter resource:

class Newsletter extends Resource{
  public function fields(Request $request)
    {
        return [
            ID::make(__('ID'), 'id')->sortable(),
           
            Text::make('Title')->sortable(),

            BelongsTo::make('Color', 'title_color_id'),

            Text::make('Description')->sortable(),

        ];
    }
}	

The Newsletter model:

class Newsletter extends Model
{
    use HasFactory;

    protected $table = 'newsletter';

    public function color()
    {
        return $this->belongsTo(Color::class);
    }

 }

Do you know what can be the issue?

0 likes
6 replies
tykus's avatar
tykus
Best Answer
Level 104

Your relationship method is called color, suggesting this should be enough:

BelongsTo::make('Color'),

But the relationship should be the following (assuming I have understood the table structure correctly)

public function color()
{
    return $this->belongsTo(Color::class, 'background_color_id');
}
1 like
OzzDev's avatar

@tykus Thanks, like that it doesnt show the error, the page is loaded but in the select menu instead of showing the color names it appears the id of the colors, do you know what can be the issue?. Also do you know how to change the text of the field so instead of have 'Color' have 'Title Color'?

tykus's avatar

@OzzDev

instead of showing the color names it appears the id of the colors

set a $title property on the Color resource:

public static $title = 'name';

do you know how to change the text of the field so instead of have 'Color' have 'Title Color'?

BelongsTo::make('Title Color', 'color', \App\Nova\Color::class),
1 like
OzzDev's avatar

@tykus Thanks, like that it shows:

{message: "Call to undefined method App\Models\Color::uriKey()", exception: "BadMethodCallException",…} exception: "BadMethodCallException" file: "/var/www/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php" line: 71 message: "Call to undefined method App\Models\Color::uriKey()" trace: [,…]

tykus's avatar

@OzzDev where is uriKey being referenced on the Color model class?

OzzDev's avatar

@tykus Thanks! I dont have nothing related to uriKey on the Color model class.

Please or to participate in this conversation.