Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'll start with a basic issue, firstly you might want to make sure all your tables are lower case (still as a snake case as well), it's not required but it's ultimately how it's expected to be with Laravel so it makes life easier to keep with that. Also a note to the wise, like Class names, database tables are typically in the singular so user instead of users</p> <p>Secondly yes you can do an insert with $user->post_likes()->save($debate); as your post_likes method on the user class returns has_many.</p> <p>Thirdly, your design of the Post_like class is a bit off, you could be better off make it like so:</p> <pre><code>class PostLike extends Eloquent { // note that PostLikes is a more standard naming for a class, they should ideally be camel case names but with all capitals for words protected $table = 'post_like'; // specifies the table the model uses public function post() // this should be singular, the naming of a belngs_to method is important as Laravel will do some of the work for you if let it { return $this-&gt;belongs_to('Post'); // by naming the method 'post' you no longer need to specify the id, Laravel will automatically know from the method name and just adding '_id' to it. } public function users() { return $this-&gt;belongs_to('User'); } } </code></pre> <p>Fourthly, your other classes could be better as:</p> <pre><code>class Post extends Eloquent { public function post_likes() { return $this-&gt;has_many('PostLike'); // doesn't require you to specify an id at all } } </code></pre> <p>I can't exactly tell you why you're getting that mass assign error, your post is a bit garbled and doesn't look like you've included the code that actually causes the exception? I have a feeling though is that you're trying to do an insert for multiple database rows at one time but haven't defined a fillable array for PostLike such as with here: <a href="http://four.laravel.com/docs/eloquent#mass-assignment" rel="nofollow">http://four.laravel.com/docs/eloquent#mass-assignment</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload