mardi 28 février 2017

Laravel Pivot Table - How to increment third field with counter?

Hi guys wondering if you can help figure out what this eloquent statement should look like. It's pretty challenging, at least for me, but maybe not for some of you guys? Here is the scenario:

I have a pivot table with post_id and user_id and an additional column called "total_views" in the pivot table.

Basically what I'm trying to do is increment the views each time the user goes and view that specific post.

This is what the SQL would look like:

UPDATE post_user SET total_views = total_views+1 WHERE user_id=1 AND post_id=2

How would you write this in an eloquent statement? Big thanks for the first that can come up with a solution!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2laxLlF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire