我正在尝试将 linguals
表与 posts
表附加在一起。我已经设置了一个包含 post_id
和 language_id
列的 language_post
表。当我尝试使用语言添加帖子时,它会出现如上所示的错误。
已检查App/Language.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Language extends Model
{
public function posts()
{
return $this->belongsToMany('App\Post')->withTimestamps();
}
}
?>
在 PostController
的方法中,public function store(Request $request)
是我收到此错误的地方
//above this all fields working perfectly
$post->save();
$post->languages()->attach($request->languages);
最佳答案
我猜你忘记对 Post 模型做同样的事情:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public function languages()
{
return $this->belongsToMany('App\Language')->withTimestamps();
}
}
关于php - 方法 Illuminate\Database\Query\Builder::languages 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56179980/