Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel雄辩,使用多态关系返回JSON结果?_Laravel_Laravel 4_Eloquent_Polymorphic Associations - Fatal编程技术网

Laravel雄辩,使用多态关系返回JSON结果?

Laravel雄辩,使用多态关系返回JSON结果?,laravel,laravel-4,eloquent,polymorphic-associations,Laravel,Laravel 4,Eloquent,Polymorphic Associations,我创建了一个多态关系,我想返回一个Json,其中包含对象与它的关系 看我的桌子“饲料” 在models/Feed.php中 class Feed extends Eloquent{ protected $table = 'feed'; public function objeto() { return $this->morphTo(); } } 在FeedController.php中 class FeedController

我创建了一个多态关系,我想返回一个Json,其中包含对象与它的关系

  • 看我的桌子“饲料”

在models/Feed.php中

class Feed extends Eloquent{
    protected $table = 'feed';

    public function objeto()
    {
        return $this->morphTo();
    }
} 
在FeedController.php中

class FeedController extends BaseController {
    public function teste(){
        return Feed::with('objeto')->get();
    }
} 
所以,我犯了这个错误

Symfony\Component\Debug\Exception\FatalErrorException

类名必须是有效的对象或字符串

如果我把这个

class FeedController extends BaseController {
    public function teste(){
        return Feed::get();
    }
} 
class FeedController extends BaseController {
    public function teste(){
        return Feed::find(1)->objeto()->get();
    }
} 
有效,但没有关系

如果我把这个

class FeedController extends BaseController {
    public function teste(){
        return Feed::get();
    }
} 
class FeedController extends BaseController {
    public function teste(){
        return Feed::find(1)->objeto()->get();
    }
} 
工作,但仅检索与此相关的对象


因此,我需要对象和关系的结果。

显示定义了多态关系的模型您是否尝试过用“Objeto”代替“Objeto”?类是否有命名空间?如果是,您必须将其包括在内