Trix Editor for Laravel

Trix Editor for Laravel

Trix is an open-source WYSIWYG editor from the creators of Basecamp and it’s designed to be a different editor. Here is how they describe it:

Most WYSIWYG editors are wrappers around HTML’s contenteditable and execCommand APIs, designed by Microsoft to support live editing of web pages in Internet Explorer 5.5, and eventually reverse-engineered and copied by other browsers.

Because these APIs were never fully specified or documented, and because WYSIWYG HTML editors are enormous in scope, each browser’s implementation has its own set of bugs and quirks, and JavaScript developers are left to resolve the inconsistencies.

Trix sidesteps these inconsistencies by treating contenteditable as an I/O device: when input makes its way to the editor, Trix converts that input into an editing operation on its internal document model, then re-renders that document back into the editor. This gives Trix complete control over what happens after every keystroke, and avoids the need to use execCommand at all.

Since Trix is CSS and JavaScript you can already integrate it with Laravel but laravel-trix is a package that makes setting it up a breeze.

First, install the Composer package:

composer require te7a-houdini/laravel-trix

Publish the assets:

php artisan vendor:publish --provider="Te7aHoudini\LaravelTrix\LaravelTrixServiceProvider"

Then, run the migrations:

php artisan migrate

Once you’ve installed the package pretend you have an articles Model and you want the Trix editor on it’s create and update forms. All you need to do is use Blade and it’s included directives:

<html>
    <head>
        @trixassets
    </head>

    <body>
        <form method="POST" action="route('article.store')">
            @csrf
            @trix(\App\Article::class, 'content')
            <input type="submit">
        </form>    
    </body>
</html>

The package includes a lot more features like handling uploaded files, rendering for existing models, and advanced configuration. You can find out more about this package from the Github page and read the full user guide.

***

This package was submitted to our Laravel News Links section. Links is a place the community can post packages and tutorials around the Laravel ecosystem. Follow along on Twitter @LaravelLinks

Filed in: News
Laravel News Partners

Laravel Jobs

Senior Full-Time Laravel Developer (REMOTE)
Remote, ANYWHERE
Vue School
Senior Laravel Developer
Remote, USA & Canada Only
Givecloud
Backend Software Engineer
Remote, USA Only
CommentSold
Full Stack Laravel Developer (Full-time/Contract)
Remote or Columbus, OH
EduSourced
Backend PHP Developer
Hamburg
ABOUT YOU GmbH

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.