Ad

How To Retrive Maximun Version Related To Post?

- 1 answer

I have two tables:

table posts
id
text

table old_posts
id 
post_id
text
version

the relation is one to many between post and old_posts when the user edits his/her post I save the old version in old_posts but I need to increment the version number so I have first to get the maximum version for that post.

how I achieve this?

Ad

Answer

in this situation, you don't need to use the version column within the database table, instead of that you just need to count the number of the old_post's rows table.

the query should be like below with eloquent:

$versions = Old_post::where('post_id', $post_id)->count(); 
Ad
source: stackoverflow.com
Ad