Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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
Connection.php第669行中的Laravel 5.2 QueryException_Php_Sql_Laravel_Laravel 5.2_Relation - Fatal编程技术网

Connection.php第669行中的Laravel 5.2 QueryException

Connection.php第669行中的Laravel 5.2 QueryException,php,sql,laravel,laravel-5.2,relation,Php,Sql,Laravel,Laravel 5.2,Relation,我正在开发一个API,但是当我创建关系(多对多)并希望在index函数中显示时,我在Connection.php第669行中得到一个错误QueryException错误提示: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'CTL_Tags.id' in 'on clause' (SQL: select `CTL_Tags`.*, `CTL_Resource_has_Tags`.`idResource` as `pivot_idRe

我正在开发一个API,但是当我创建关系(多对多)并希望在
index
函数中显示时,我在Connection.php第669行中得到一个错误
QueryException
错误提示:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'CTL_Tags.id' in 'on clause' (SQL: select `CTL_Tags`.*, `CTL_Resource_has_Tags`.`idResource` as `pivot_idResource`, `CTL_Resource_has_Tags`.`idTag` as `pivot_idTag` from `CTL_Tags` inner join `CTL_Resource_has_Tags` on `CTL_Tags`.`id` = `CTL_Resource_has_Tags`.`idTag` where `CTL_Resource_has_Tags`.`idResource` is null)
我相信我的错误在我的模型中,因为它在
CTL_标签
表中查找
id
,而该表中我的id名称是
idTag

这是我的CTL_资源模型

<?php

namespace Knotion;

use Illuminate\Database\Eloquent\Model;

class CTL_Resource extends Model  {
    public $timestamps = false;

    protected $table = "CTL_Resource";

    protected $hidden = [
      'coachVisibility', 'thumbnail', 'tags', 'relatedTo',
      'studentVisibility', 'isHTML','studentIndex', 'coachIndex',
      'isURL', 'source', 'path', 'status', 'updateTime', 'isfolder',
      'parentResource', 'idModifierUser'
    ];

    protected $fillable = ['idResourceType','productionKey', 'tags', 'idCreatorUser', 'idModifierUser', 'idCreationCountry', 'title', 'description', 'URL', 'fileName', 'extension', 'quicktag', 'minimumAge', 'maximumAge', 'productionKey'];

    public function creatorUser() {
      return $this->belongsTo('Knotion\OPR_User', 'idCreatorUser');
    }
    public function creationCountry() {
      return $this->belongsTo('Knotion\CTL_Country', 'idCreationCountry');
    }
    public function resourceType()  {
      return $this->belongsTo('Knotion\CTL_ResourceType', 'idResourceType');
    }
    public function quickTags() {
      return $this->belongsToMany('Knotion\CTL_QuickTag', 'CTL_Resource_has_QuickTags', 'idResource', 'idQuickTag');
    }
    public function tags() {
      return $this->belongsToMany('Knotion\CTL_Tag','CTL_Resource_has_Tags', 'idResource', 'idTag');
    }
    public function relatedTo() {
      return $this->belongsToMany('Knotion\CTL_RelatedTo', 'CTL_Resource_has_RelatedTo', 'idResource', 'idRelatedTo');
    }

}
尝试定义

$primaryKey
在模型中,使用正确的列名


谢谢,先生,它成功了!错误已经消失,但我看不到关系,它看起来是一个空数组,但我认为这是另一个问题。非常感谢。:)
<?php

namespace Knotion\Http\Controllers;

use Illuminate\Http\Request;
use Knotion\Http\Requests;
use Knotion\Http\Requests\ResourcesRequest;

use Knotion\CTL_Resource;
use Knotion\CTL_Tag;
use Knotion\CTL_QuickTag;
use Knotion\CTL_RelatedTo;
use Knotion\CTL_ResourceType;


class ResourcesController extends Controller  {

    public function index(Request $request)    {

        $resources = CTL_Resource::paginate(10);

        $resources->each(function($resources) {
          $resources->tags;
          $resources->quickTags;
          $resources->relatedTo;
        });

        return response()->json(
          $resources
      );
$primaryKey