在模型[App \ Models \ Area]上调用未定义的关系[]

时间:2017-01-12 09:42:43

标签: php laravel

调用以下操作时:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Karellens\LAF\Http\Controllers\ApiController;
use Karellens\LAF\Facades\QueryMap;

class AreasController extends ApiController
{
    public function with_popular_descendants(Request $request)
    {
        $relations = QueryMap::explodeFields(request()->input('fields'));
        $relations['lower'] = function ($q) {
            $q->where('popular', 1);
        };

        return \App\Models\Area
            ::with($relations)
            ->where('area_type', 0)
            ->paginate($request->input('pagesize', 100))
            ->toArray()
            ;
    }
}

我收到错误:在模型[App \ Models \ Area]上调用未定义的关系[]

在本地服务器上,我没有此错误,仅在生产时。我检查了DB,是的有桌面区域。我打电话给工匠修补匠并手动选择所有区域。

$ relations返回以下代码:

array(2) {
  [0]=>
  string(0) ""
  ["lower"]=>
  object(Closure)#355 (2) {
    ["this"]=>
    object(App\Http\Controllers\AreasController)#305 (5) {
      ["version":protected]=>
      string(0) ""
      ["alias":protected]=>
      string(4) "area"
      ["modelClass":protected]=>
      string(16) "\App\Models\Area"
      ["middleware":protected]=>
      array(0) {
      }
      ["validatesRequestErrorBag":protected]=>
      NULL
    }
    ["parameter"]=>
    array(1) {
      ["$q"]=>
      string(10) "<required>"
    }
  }
}

0 个答案:

没有答案