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

twg_'s avatar
Level 6

Issue with BelongsTo on self

I'm having an issue with a BelongsTo that points to itself.

App/Models/Categories.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Categories extends Model
{
	public function getParent()
	{
		return $this->belongsTo(SELF::class, 'parent_id', 'id');
	}

	public function getChildren()
	{
		return $this->hasMany(SELF::class, 'parent_id', 'id');
	}
}

App/Nova/Category.php

<?php

namespace App\Nova;

class Category extends Resource
{
	public function fields(Request $request)
	{
		return [
			ID::make()->sortable(),
			BelongsTo::make('Parent Category', 'getParent', SELF::class)->nullable()
		];
	}
}

I keep getting an error of Call to undefined method App\Nova\Category::fieldsMethod().

0 likes
1 reply

Please or to participate in this conversation.