如果有人碰巧找到這個,這是我最終不得不做的。我正在使用Laravel 5.3:
/*Game Model*/
public function images()
{
return $this->morphMany('App\Image', 'imageable');
}
/*Image Model*/
public function imageable()
{
return $this->morphTo();
}
/*Games Controller*/
public function index()
{
$games = Game::with('images')->get();
return $games;
}
=====================================
Here is the JSON it returns:
{
id: 1,
title: "As she said to.",
slug: "as-she-said-to",
description: "Consequatur at qui iusto.",
created_at: "2016-09-29 12:04:36",
updated_at: "2016-09-29 12:04:36",
images: [
{
id: 1,
url: "http://www.mobygames.com/images/covers/l/281002-rayman-legends-xbox-one-front-cover.png",
imageable_id: 1,
imageable_type: "App\Game",
created_at: "2016-09-29 12:04:36",
updated_at: "2016-09-29 12:04:36"
}
]
}
========================================
Then in my Vue.js front-end:
<img v-bind:src="game.images[0].url" class="img-responsive"/>
現在檢查了這一點。我會讓你知道的。謝謝你的回答,而不是downvote :) – plushyObject
這非常接近我正在尋找的東西。我能夠在Laravel 5中找到更多有關急切加載的信息,並使其工作。萬分感謝!它絕對迷失在Laravel的文檔中,所以非常感謝 – plushyObject