Laravel 拉威尔与联盟/分形有着许多粗略的关系

Laravel 拉威尔与联盟/分形有着许多粗略的关系,laravel,laravel-5,lumen,Laravel,Laravel 5,Lumen,我正在努力让我的头围绕着一个拉拉维尔哈斯曼圈和联盟/分形变形金刚 我有三张桌子: Countries: -id (int) -other fields ... Cities: -id (int) -country_id (int) -other fields ... Users -id (int) -city_id (string) -some other ... 我试图通过Cities表关系从Country访问Users关系

我正在努力让我的头围绕着一个拉拉维尔哈斯曼圈和联盟/分形变形金刚

我有三张桌子:

Countries:
    -id (int)
    -other fields ...

Cities:
    -id (int)
    -country_id (int)
    -other fields ...

Users
    -id (int)
    -city_id (string)
    -some other ...
我试图通过Cities表关系从Country访问Users关系,该表使用以下雄辩的查询:

$countryUsers = Country::with('users')->where('id', $id)->get();
但是当我试图使用$fractal来转换这个关系时,我得到了分割错误(内核转储)错误

在国内,我有:

class CountryController extends ApiController
{

     protected $manager;

        function __construct(Manager $manager) {

            $this->manager = $manager;

        }

    public function show(CountryTransformer $countryTransformer, $id) {


        $country = Country::find($id);

        return $this->respondItem($country, $countryTransformer);


    }


    public function respondItem($item, $transformer)

        {

            $this->manager->setSerializer(new CustomArraySerializer());

            $resource = new Item($item, $transformer);

            $data = $this->manager->createData($resource)->toArray();

            return $this->respond($data);

        }
在我的国家模式中,我有:

public function users() {

    return $this->hasManyThrough('App\Models\User', 'App\Models\City');
}

public function cities() {

    return $this->hasMany('App\Model\City');
}
城市模式:

 public function country() {
        return $this->belongsTo('App\Models\Country');
    }
用户模型:

 public function city()
    {
        return $this->belongsTo('App\Models\City');
    }
和国家变压器:

<?php namespace App\Transformers;


use App\Models\Country;

use League\Fractal\TransformerAbstract;

class CountryTransformer extends TransformerAbstract {

    protected $defaultIncludes = [
        'users'
    ];

    public function transform(Country $country)
    {
        return [
            'id'            => $country->id,
            'name'          => $country->name,
            'code'          => $country->code,
            'time_zone'     => $country->time_zone,
            'active'        => $country->active,
            'status'        => $country->status,
            'params'        => $country->params
        ];
    }

    public function includeUsers(Country $country)
    {

        $users = $country->users;

        if ($users) {
            return $this->collection($users, new UserTransformer());
        }
    }

}