abkrim
2 months ago
722
6
Nova

HasOne not show anything

Posted 2 months ago by abkrim

Laravel Nova 3.1.0 / Laravel 7.2.1

Models

Server

class Server extends Model
{
    use SoftDeletes, CascadeSoftDeletes;

    protected $guarded = [];


    public function provider()
    {
        return $this->hasOne('App\Provider');
    }

}

Provider

class Provider extends Model
{
    protected $guarded = [];

    public function server()
    {
        return $this->belongsTo('App\Server');
    }
}

Nova Resources

Server

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

		Text::make('FQDN')->sortable()->rules('required', 'max:255'),
		Text::make('alias')->sortable()->rules('max:255'),

		HasOne::make('Proveedor', 'provider', 'App\Nova\Provider')

		// Try also 
		// 	HasOne::make('Provider')
	];
}

Provider

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

		Text::make('Nombre', 'name')->sortable()->rules('required', 'max:100'),
		Text::make('Teléfono','telephone')->rules('max:20'),
		Textarea::make('Notas','notes')->alwaysShow(),
	];
}
  • On table Provider has two providers.
  • Table providers has a provider_id column.

I don't see my mistake ... I've been head butting all morning

Please sign in or create an account to participate in this conversation.