Download the PHP package edujugon/tablediff without Composer
On this page you can find all versions of the php package edujugon/tablediff. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download edujugon/tablediff
More information about edujugon/tablediff
Files in edujugon/tablediff
Package tablediff
Short Description Comparing DB tables data for Laravel
License MIT
Informations about the package tablediff
TableDiff
Comparing DB tables data for Laravel.
Installation
type in console:
Register TableDiff service by adding it to the providers array.
Let's add the Alias facade, add it to the aliases array.
Usage samples
Instance the main TableDiff class:
Add tables to be compared
Set the pivots
If the columns have the same name you could do it like follows:
Now, we can run the comparison and get the report
Of course, all those methods can be chained
Notice if you don't use
column
method, it will look for all columns with same name in both tables.
Merging
The simplest way yo do a merge is like follows
The above code snippet will update the column_to_update
column values from base_table
with the column_to_update
column values of merge_table in matched ids.
Notice that
merge
method will update the matched records and also add those records that are new for base table.
Just merging matched records
Now, let's insert the new records.
merge
, mergeMatched
and mergeUnMatched
methods accept callbacks before doing the merge and just after each update.
Before callback is perfect for casting data like. It takes the data which will be added.
The first callback is call each time the db is updated. It takes the collection to be updated and the data with the new values
In case of mergeUnMatched
, the first callback takes the new elements to be added and is called for each chunk (By default 10)
Event
Once the merge is done the package fires an event call Edujugon\TableDiff\Events\MergeDone
with some useful parameters
Parameters:
- Merge type
- Report
- Extra payload
Extra payload can be anything you want to add the the event
Kepp in mind that
eventPayload
method have to be called before callingmerge
method.
That is perfect when need to do some actions after merging like store it in db, send notification, etc..