laravel - How do I get just the most recent set of changes in the revisionable package? -


currently have revisionable trait correctly storing , fetching history of model goes through change.

each update model creates record per field changed.

is possible group records change?

example time:

round 1

$model = mymodel::find(1); $model->a = 5; $model->b = 6; $model->save(); 

this results in following entries

+----------+--------+-----+-----------+-----------+--------------+ | rev_type | rev_id | key | old_value | new_value |  created_at  | +----------+--------+-----+-----------+-----------+--------------+ | mymodel  |      1 |   |         0 |         5 | [first date] | | mymodel  |      1 | b   |         0 |         6 | [first date] | +----------+--------+-----+-----------+-----------+--------------+ 

round 2

$model = mymodel::find(1); $model->a = 555; $model->b = 666; $model->save(); 

this results in following entries

+----------+--------+-----+-----------+-----------+---------------+ | rev_type | rev_id | key | old_value | new_value |  created_at   | +----------+--------+-----+-----------+-----------+---------------+ | mymodel  |      1 |   |         0 |         5 | [first date]  | | mymodel  |      1 | b   |         0 |         6 | [first date]  | | mymodel  |      1 |   |         5 |       555 | [second date] | | mymodel  |      1 | b   |         6 |       666 | [second date] | +----------+--------+-----+-----------+-----------+---------------+ 

in case, want grab records 3 , 4.

initial thinking includes fetching , grouping created_at date, fetching last group (the recent date). don't know if there guarantee dates identical.

is there way group update when retrieving history revisionable?

edit

upon deeper investigation - revisionable created_at date using built in ->withtimestamps() trait. each insert in batch insert (like 1 revisionable uses), fresh timestamp grabbed carbon date, means (from understanding) batch insert have different created_at dates.

there 2 possibilities:

first one: search latest entry

$latestdate = changes::orderby('created_at' 'desc')->first()->created_at; $latestentries = changes::where('created_at', $latestdate)->get(); 

but it's not 100% because when time changes between inserts wrong results.

so better use way:

add column count changes. everytime make change (in case add 2 new lines), increase integer one. know changes made first, second , on.

//get latest changes $latestchange = changes::orderby('created_at' 'desc')->first()->saveid; $latestentries = changes::where('savedid', $latestchange)->get(); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -