<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class CategoryPlan extends Model
{
     public static function savePlans($type_id, $plans) {

            $i = 0;
            foreach ($plans as $plan) {
                
                   $id=$plan['id'];
               $plan['type_id']=$type_id;
               unset($plan['url']);
               if (!isset($plan['status'])) {
                   $plan['status']=1;
               }else{
                     $plan['status']=0;
               }
                if (empty($id)) {
                    if (!isset($plan['remove'])) {
                        $array["created_at"] = date("Y-m-d H:i:s");
                        self::insertGetId($plan);
                    }else{
                        
                    }
                } else {
                    if (!isset($plan['remove'])) {
                       self::where("id", $id)->update($plan); 
                    }else{
                        self::where("id", $id)->delete(); 
                    }
                    
                }
                $i++; 
                
               
            }
        
    }
}
