PHPackages                             guillermo-rod/convert-string-to-file - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. guillermo-rod/convert-string-to-file

ActiveLibrary[File &amp; Storage](/categories/file-storage)

guillermo-rod/convert-string-to-file
====================================

Converts rich text to file (html, css, js, etc..), useful when you needs print rich text but on secure mode.

v1.0.0(2y ago)123MITPHP

Since Jul 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Guillermo-Rod/convert-string-to-file)[ Packagist](https://packagist.org/packages/guillermo-rod/convert-string-to-file)[ RSS](/packages/guillermo-rod-convert-string-to-file/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel - Rich String to File
=============================

[](#laravel---rich-string-to-file)

*Converts rich string to css, js, html or text files*

Publish table and config
------------------------

[](#publish-table-and-config)

`php artisan vendor:publish --tag="string-to-file:migrations"`

`php artisan vendor:publish --tag="string-to-file:config"`

Trait methods
-------------

[](#trait-methods)

```
    class Product extends Model {

        use \GuillermoRod\StringToFile\ConvertsStringToFile;

        /**
         * Return the model properties configuration array for create the files for this model.
         *
         * @return array
         */
        public function convertStringToFile(): array
        {
            return ['description', 'details', 'data_sheet'];
        }
    }

    // .. Some controller method
    $product   = Product::with('string_files')->first();
    $attribute = 'details';

    // Determine if the file was created
    $product->hasStringFile($attribute); // : bool

    // Get the model instance that belongs to the attribute,
    // Inside of model there are more methods
    $product->getStringFile($attribute); // : \GuillermoRod\StringToFile\Models\StringToFile

    // If the file extension is css or js, get the url
    $product->getStringFileUrlAsset($attribute); // : string

    // If the file extension is html, get view path
    $product->getStringFileViewPath($attribute); // : string

    // Get the file contents
    $product->getStringFileContents($attribute); // : string
```

Config Options
--------------

[](#config-options)

```
    class Product extends Model {

        use \GuillermoRod\StringToFile\ConvertsStringToFile;

        /**
         * Return the model properties configuration array for create the files for this model.
         *
         * @return array
         */
        public function convertStringToFile(): array
        {
            return [
                'description' => [
                    'extension' => \GuillermoRod\StringToFile\Models\StringToFile::HTML_EXTENSION
                ],
                'styles' => [
                    'extension' => \GuillermoRod\StringToFile\Models\StringToFile::CSS_EXTENSION
                ],
                'details' => [
                    'extension' => \GuillermoRod\StringToFile\Models\StringToFile::JS_EXTENSION
                ],
                'data_sheet' => [
                    'extension' => \GuillermoRod\StringToFile\Models\StringToFile::TXT_EXTENSION
                ],
            ];
        }
    }

```

Observer class
--------------

[](#observer-class)

The conversions are generated automatically after save the model

```
    $product = Product::first();

    // create or update content
    $product->details = 'New content';
    $product->save();

    // Updating model but not affect to the file content, No changes
    $product->some_another_field = 'product_1';
    $product->save();

    // Deleting file
    $product->details = null;
    $product->save();

    $newProduct = new Product;
    $newProduct->details = 'Hello';
    $newProduct->save();
```

Blade Directives
----------------

[](#blade-directives)

```
    // .. Some controller method
    $product = Product::with('string_files')->first();

    return view('test', compact('product')),
```

```
    //.. test.blade.php

    /**
     * @param \Illuminate\Database\Eloquent\Model $model
     * @param string $attribute
     * @param string $richText - default value to show if file not exists
     */
    @includeHtmlFromString($product, 'details', $product->details) // : html content
    @includeFileContentsFromString($product, 'details', $product->details) // : string

    /**
     * @param \Illuminate\Database\Eloquent\Model $model
     * @param string $attribute
     * @param string $richText - default value to show if file not exists
     * @param string $mergeElementAttributes defer, fingerprint="" etc..
     */
    @includeStyleFromString($product, 'details', $product->details) // :  and $default for default value
    @includeScriptFromString($product, 'details', $product->details, 'defer') // :  and $default for default value

    // Define manually scripts
    @if ($product->hasStringFile('details'))

    @else

            function some() {/* ... */}

    @endif

    // Define manually styles
    @if ($product->hasStringFile('details'))

    @else

            .some-class {/* ... */}

    @endif

    //Define manually content
    @if ($product->hasStringFile('details'))
        {{ $product->getStringFileContents() }}
    @else
        {{-- ... some --}}
    @endif
```

Regenerate files
----------------

[](#regenerate-files)

You can regenerate the files executing the nex command

`php artisan string-to-file:regenerate {modelType}`

**php artisan string-to-file:regenerate "App\\Models\\Product"**

Author
------

[](#author)

Guillermo Rodriguez

Contributions
-------------

[](#contributions)

If you want to make tests, you may send me a email :)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1034d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb0c3a841bb1d97e67b777754fc32c6fa71e01308016b9c812f3442dc3d4cebf?d=identicon)[Guillermo-Rod](/maintainers/Guillermo-Rod)

---

Tags

convert-string-to-filelaravellaravel-frameworkshow-ckeditor-result

### Embed Badge

![Health badge](/badges/guillermo-rod-convert-string-to-file/health.svg)

```
[![Health](https://phpackages.com/badges/guillermo-rod-convert-string-to-file/health.svg)](https://phpackages.com/packages/guillermo-rod-convert-string-to-file)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M124](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
