You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to clone a model with relations that are MorphToMany but am getting an error on this. My Form model can be associated to many Site models in my project via a model called Siteable. My Siteable table looks like:
Schema::create('siteables', function (Blueprint$table) {
$table->ulid('id')->primary()->index();
$table->foreignUlid('site_id')->index()->constrained()->onUpdate('cascade')->onDelete('cascade');
$table->ulidMorphs('siteable');
$table->timestamps();
// define indexes for performance$table->index(['site_id', 'siteable_type', 'siteable_id']);
$table->index('created_at');
});
When trying to clone my Form, with the linked Siteable model, I get an error despite adding the following to my my Form model:
For reference, these are the two relations in my Form:
/** * Get the site for the form */publicfunctionsite(): HasOneThrough
{
return$this->hasOneThrough(
Site::class,
Siteable::class,
'siteable_id',
'id',
'id',
'site_id'
)->where('siteable_type', Form::class);
}
/** * Get all of the sites for the form. */publicfunctionsites(): MorphToMany
{
return$this->morphToMany(Site::class, 'siteable')->withPivot('id');
}
The error is:
Call to undefined method Illuminate\Database\Eloquent\Relations\HasOneThrough::save()
The text was updated successfully, but these errors were encountered:
Hi, I'm trying to clone a model with relations that are
MorphToMany
but am getting an error on this. MyForm
model can be associated to manySite
models in my project via a model calledSiteable
. MySiteable
table looks like:When trying to clone my
Form
, with the linkedSiteable
model, I get an error despite adding the following to my myForm
model:For reference, these are the two relations in my
Form
:The error is:
The text was updated successfully, but these errors were encountered: