Beispiel #1
0
 public static function saveBundle($postId, array $bundle)
 {
     // Remove all previous post meta
     PostMeta::where('post_id', $postId)->delete();
     // Insert new post meta
     foreach ($bundle as $bundleKey => $bundleValue) {
         // encode to json if meta value is an array
         if (is_array($bundleValue)) {
             $bundleValue = json_encode($bundleValue);
         }
         PostMeta::create(['post_id' => $postId, 'meta_key' => $bundleKey, 'meta_value' => $bundleValue]);
     }
 }