Skip to content

Commit 7562779

Browse files
committed
Update 3.relationships.md
1 parent cf4880d commit 7562779

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

content/3.resources/3.relationships.md

+20
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ MorphTo::make('commentable', PostResource::class),
156156

157157
::callout{icon="i-heroicons-exclamation-triangle" color="amber"}
158158
You must specify multiple relations for each morph to resource possible. Please consider declaring multiple relations in your model.
159+
160+
::collapsible{name="relations"}
161+
```php
162+
// You can't declare this relation in Laravel Rest Api
163+
public function commentable(): MorphTo
164+
{
165+
return $this->morphTo();
166+
}
167+
168+
public function post(): MorphTo
169+
{
170+
return $this->morphTo()->where('commentable_type', Post::class);
171+
}
172+
173+
public function video(): MorphTo
174+
{
175+
return $this->morphTo()->where('commentable_type', Video::class);
176+
}
177+
```
178+
::
159179
::
160180

161181
## Morph To Many

0 commit comments

Comments
 (0)