私は自分のウェブサイトのようなシステムを作成していました。これで、1人のユーザーが投稿に対して1回だけいいねできるようにしたかったのです。そして、投稿は多くのユーザーに好かれます。また、多くのユーザーが多くの投稿に「いいね!」をすることができます。
したがって、私が正しく推測すると、それは多対多の関係です。
このコンテキストでは、次のテーブルを作成します
... ユーザー テーブル:
id
name
.... 投稿テーブル:
id
post
...post_likes テーブル
ID
user id
poost_id
今、私は次のモデルを持っています
ユーザー:
class User extends SentryUserModel {
public function post_likes()
{
return $this->has_many('Post_like', 'id');
}
}
役職 :
class Post extends Eloquent {
public function post_likes()
{
return $this->has_many('Post_like', 'id');
}
}
post_like :
class Post_like extends Eloquent {
public function posts()
{
return $this->belongs_to('Post', 'post_id');
}
public function users()
{
return $this->belongs_to('User', 'user_id');
}
}
データベースに挿入しようとすると(post_likesテーブル用)、というエラーが発生します
Illuminate \ Database \ Eloquent \ MassAssignmentException
user_id
また、次のようなデータベースに挿入する方法があることを知りたい
$user->like()->save($user); ?????
前もって感謝します。ハッピーコーディング。\m/