Answer the question
In order to leave comments, you need to log in
Where to use one-to-one polymorphic relationships?
I did the One To One (Polymorphic) dock, it works, but I haven’t entered it yet, when to use it, give me simple tasks so that I can fully figure it out for One To One (Polymorphic).
There are no examples in the dock at all.
I made 1 example, that's what happened, am I right in general? post
model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public function image()
{
return $this->morphOne('App\Image', 'imageable');
}
}
$post = Post::find(1);
$image = $post->image;
dump($post);
dump(User::find($post->user_id));
dump($image);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question