Level 6
Can u please provide an example of how u use this method?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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().
Please or to participate in this conversation.