0
votes

This is my "Standard" resource's code

class Standard extends Resource
{

    public static $model = '\\PackageName\\Http\\Models\\Standard';

    public static $title = 'parent_id';

    public static $search = [
        'id',
    ];

    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Text::make('ASN Id', 'short_asn_id')
            ->sortable(),

            BelongsTo::make('Parent', 'getParent', 'app\Nova\Standard'),
            HasMany::make('Children', 'getchildren', 'app\Nova\Standard'),
        ];
    }
}

And Model Code like this =>

public function getParent()
{
    return $this->belongsTo(static::class, 'parent_id');
}

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

I want to establish parent child relationship on same table. Unfortunately I am constantly getting "Class name must be valid object or string" error.

I tried passing class name like \App\Nova\Standard::class Not working.

I am new in Nova and could not figure out exact issue.

Nova version is latest. Laravel version is 5.7

1

1 Answers

0
votes

Double check your model & resource namespace.

Why there is \\ in your $model attribute ? Usually the namespace App\Standard, if you have different namespace modify accordingly. Usually the app in the namespace is capital, App\Nova\Standard

class Standard extends Resource
{

    public static $model = 'App\Standard'; // Modify according to your namespace
    ...

    BelongsTo::make('Parent', 'getParent', 'App\Nova\Standard'), // Capital A
}