app\helpers\FileWorker::workInModel PHP Method

workInModel() protected static method

protected static workInModel ( $modelName, $fieldName, $type )
    protected static function workInModel($modelName, $fieldName, $type)
    {
        $path = APP_PATH . 'Models/' . $modelName . '.php';
        $file_contents = file_get_contents($path);
        $cl = "App\\Models\\{$modelName}";
        $model = new $cl();
        $fillable = $model->getFillable();
        if ($type == 'add') {
            if (array_search($fieldName, $fillable) === false) {
                $fillable[] = $fieldName;
            }
        } elseif ($type == 'remove') {
            if (($k = array_search($fieldName, $fillable)) !== false) {
                unset($fillable[$k]);
            }
        }
        $strData = var_export($fillable, true);
        if (preg_match('/protected \\$fillable = ([^;]+);(\\r|\\n)/', $file_contents, $m)) {
            self::replaseInFile($path, $m[1], $strData);
        }
    }