morphedByMany的用法

<?php
/**

  • Created by PhpStorm.

  • User: Administrator

  • Date: 2017/7/31

  • Time: 10:29
    */

namespace App\Api\V1\Models;

use Illuminate\Database\Eloquent\Model;

class Tags extends Model
{

protected $table ='tags';
public function news()
{
    return $this->morphedByMany(News::class,'tags');
}
public function lessons()
{
    return $this->morphedByMany(Lesson::class);
}

}

这是我的Model代码

这是报错
{"message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags.tags_id' in 'field list' (SQL: select news.*, tags.tags_id as pivot_tags_id from news inner join tags on news.id = tags.tags_id where tags.tags_id = 1 and tags.tags_type = App\\Api\\V1\\Models\\News)","code":"42S22","status_code":500}

定义关系那里,后面加两个参数 tags_id, id, 如果还反,换成id,tags_id试试

BallOon
修改的评论也不能少于六个字哦!
JellyBool 回复 BallOon
修改的评论也不能少于六个字哦!
BallOon 回复 JellyBool
修改的评论也不能少于六个字哦!
tufeiax123
修改的评论也不能少于六个字哦!
BallOon 回复 tufeiax123
修改的评论也不能少于六个字哦!