From a90ba8116f5c12181208e19ddf1689c82da77396 Mon Sep 17 00:00:00 2001 From: Vernard Alexis Luz Date: Sat, 12 Nov 2016 21:28:13 +0800 Subject: [PATCH] Add flexibility to allow the application to modify the model before saving --- .../SyncableGraphNodeTrait.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/LaravelFacebookSdk/SyncableGraphNodeTrait.php b/src/LaravelFacebookSdk/SyncableGraphNodeTrait.php index 05afe8d..abf0950 100644 --- a/src/LaravelFacebookSdk/SyncableGraphNodeTrait.php +++ b/src/LaravelFacebookSdk/SyncableGraphNodeTrait.php @@ -37,6 +37,24 @@ trait SyncableGraphNodeTrait * @throws \InvalidArgumentException */ public static function createOrUpdateGraphNode($data) + { + $graph_node = static::convertGraphNodeToModel($data); + + $graph_node->save(); + + return $graph_node; + } + + /** + * Converts Graph node into a Model so that any changes can be done before saving + * + * @param $data + * + * @return Model + * + * @throws \InvalidArgumentException + */ + public static function convertGraphNodeToModel($data) { // @todo this will be GraphNode soon if ($data instanceof GraphObject || $data instanceof GraphNode) { @@ -55,8 +73,6 @@ public static function createOrUpdateGraphNode($data) static::mapGraphNodeFieldNamesToDatabaseColumnNames($graph_node, $data); - $graph_node->save(); - return $graph_node; }