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

nnachev's avatar

Filament form nested repeater relationship error "Target class [] does not exist."

Hello. I have a form containing two nested repeater fields with relationships in the resource file. OrderResource.php

class OrderResource extends Resource {

  public static function form(Form $form): Form {
	return $form
		->schema([
			Forms\Components\TextInput::make(('number')),
			Forms\Components\Repeater::make('materials')
				->relationship('materials')
				->schema([
					Forms\Components\TextInput::make('color'),
					forms\Components\Repeater::make('materialPhotos')
						->relationship('materialPhotos')
						->schema([
							Forms\Components\TextInput::make('materialPhoto'),
						]),
				]),
		]);
	}
}

I have three models for the three database tables.

1- Order.php for the resource file. - There is relation to the model Material.php

class Order extends Model {
// Get the Order materials.
 public function materials(): HasMany {
    return $this->hasMany(Material::class, 'order_id');
  }
}

2- Material.php - There is the relation to the model MaterialPhoto.php

class Material extends Model {
 // Get the parent order
 public function order(): BelongsTo {
    return $this->belongsTo(Order::class, 'order_id');
  }

// Get the material photos.
 public function materialPhotos(): HasMany {
    return $this->hasMany(MaterialPhoto::class, 'material_id');
  }

 // Save model
 public function save(array $options = []) {
    // Call parent Save method
    parent::save($options);

	// Custom logic.
}

3- MaterialPhoto.php

class MaterialPhoto extends Model {
 // Get the parent Material
 public function material(): BelongsTo {
    return $this->belongsTo(Material::class, 'material_id');
  }

EDIT: I have custom Save method in model Material.php. Call of parent::save($options); brake the code.

When I try to submit the form to create a new record error message appeared "Target class [] does not exist." I suggest that the nested repeater relationship cannot be created during the creation because does not find the ID of the Material ore something in this context. I don't know why this happens and don't know how to solve this error. If I Edit record I can add material photos in the nested repeater without any errors. How to solve this issue? How to submit the form on Create record and save the data in nested relations?

EDIT2: I found where was the problem. I've forgotten to return a value in my custom function save. Correct syntax of function is:

 // Save model
 public function save(array $options = []) {
    // Call parent Save method
    parent::save($options);

	// Custom logic.

	return $saved
}

Best regards.

0 likes
0 replies

Please or to participate in this conversation.