Answer the question
In order to leave comments, you need to log in
Why doesn't morphTo work?
The database has a table of files:
Schema::create('files', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->uuid('fileable_id');
$table->string('fileable_type');
$table->timestamps();
});
Schema::create('images', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->timestamps();
});
class File extends Model
{
public function fileable()
{
$this->morphTo();
}
class Image extends Model
{
public function file()
{
return $this->morphOne(File::class, 'fileable');
}
$image->file
$file->fileable
"message" => "App\Models\File\File::fileable must return a relationship instance."
$file->fileable()
it returns null. But after all, the file can be found through the picture ... I morphTo();
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