【问题标题】:article get wrong categories in eloquent laravel 5.5文章在 eloquent laravel 5.5 中分类错误
【发布时间】:2018-08-07 13:50:07
【问题描述】:

我卡在我的代码中,我的文章中的类别有误,关于详细信息,我将展示我的代码,

Artikel model

    class Artikel extends Model
{
    protected $fillable = [
        'judul', 'kutipan', 'slug', 'kategori_id','tag_id', 'isi', 'meta_keyword', 'meta_deskripsi', 'foto', 'status'
    ];

    protected $table = 'artikel';

    public function kategori(){
        return $this->belongsTo('App\Kategori','id');
    }
}

这是我的分类模型

protected $fillable = ['nama_kategori', 'slug'];
protected $table = 'kategori';

public function tag()
{
    return $this->belongsTo('App\Tag','kategori_id');
}

public function artikel()
{
    return $this->hasMany('App\Artikel','kategori_id');
}

当我在 php artisan tinker 上尝试这个时

Artikel::with('categori')->where('slug','coba123')->get();

结果这样出错,

有人可以帮助我吗?这让我很困惑,我也有谷歌搜索但仍然没有改变结果..

【问题讨论】:

    标签: mysql orm laravel-5.5 laravel-eloquent


    【解决方案1】:

    您使用了错误的列:

    public function kategori(){
        return $this->belongsTo('App\Kategori','kategori_id');
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-07
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 2018-02-14
      • 2019-08-15
      • 2018-02-13
      • 2018-10-31
      • 1970-01-01
      相关资源
      最近更新 更多