Integrates the Trix Editor with Laravel. Inspired by the Action Text gem from Rails.
MIT License
Bot releases are visible (Hide)
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/3.0.0...3.1.0
Published by tonysm 7 months ago
encryptString
and decryptString
by @tonysm in https://github.com/tonysm/rich-text-laravel/pull/53
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.2.0...3.0.0
In 2.2.0 we introduced a new recommended way to encrypt data, which uses Laravel's Crypt::encryptString()
instead of Crypt::encrypt()
. This is now the default in v3. If you're migrating from 2.x and have existing data stored encrypted, but not using the recommendation in the 2.2.0 release note, you must migrate them (see instructions below).
If you only have encrypted rich text attributes in your application, you may create a new migration and loop through the stored data, encrypting and decrypting it:
DB::table('rich_texts')->whereNotNull('body')->eachById(function ($richText) {
DB::table('rich_texts')
->where('id', $richText->id)
->update([
'body' => Crypt::encryptString(Crypt::decrypt($richText->body)),
]);
});
If you have a mix of encrypted and plain text rich text attributes, you will have to check if the $richText->field
and $richText->record_type
fields match the entities and attribute that are using encryption:
DB::table('rich_texts')
->whereNotNull('body')
->where('field', 'content')
->where('record_type', (new Post())->getMorphClass())
->eachById(function ($richText) {
DB::table('rich_texts')
->where('id', $richText->id)
->update([
'body' => Crypt::encryptString(Crypt::decrypt($richText->body)),
]);
});
Published by tonysm 7 months ago
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.1.0...2.2.0
It's now recommended that you add a RichTextLaravel::encryptAsString()
to your AppServiceProvider::boot
method. If you have existing data stored encrypted, you'll have to migrate them manually (see instructions below). This is an opt-in feature, but it's highly recommended to store encrypted rich text attributes as string (the default way will serialize the value before encrypting, which is not needed).
In the next major version, we'll switch to encrypt as string by default.
If you only have encrypted rich text attributes in your application, you may create a new migration and loop through the stored data, encrypting and decrypting it:
DB::table('rich_texts')->whereNotNull('body')->eachById(function ($richText) {
DB::table('rich_texts')
->where('id', $richText->id)
->update([
'body' => Crypt::encryptString(Crypt::decrypt($richText->body)),
]);
});
Make sure you add the RichTextLaravel::encryptAsString()
to your AppServiceProvider::boot
method.
If you have a mix of encrypted and plain text rich text attributes, you will have to check if the $richText->field
and $richText->record_type
fields match the entities and attribute that are using encryption:
DB::table('rich_texts')
->whereNotNull('body')
->where('field', 'content')
->where('record_type', (new Post())->getMorphClass())
->eachById(function ($richText) {
DB::table('rich_texts')
->where('id', $richText->id)
->update([
'body' => Crypt::encryptString(Crypt::decrypt($richText->body)),
]);
});
Published by tonysm 8 months ago
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.0.3...2.1.0
Published by tonysm 8 months ago
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.0.2...2.0.3
Published by tonysm 8 months ago
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.0.1...2.0.2
Published by tonysm 8 months ago
Published by tonysm 8 months ago
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/1.7.0...2.0.0
A few things changed from v1. There are some breaking changes, but most are renamings.
Rename all your $richTextFields
properties to $richTextAttributes
on all your models using it
Rename the <x-rich-text-trix-styles />
to <x-rich-text::styles />
Rename the <x-trix-field />
to <x-trix-input />
(both the file and its usages)
Published by tonysm 8 months ago
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.0.0-beta.3...2.0.0-beta.4
Published by tonysm 8 months ago
<x-rich-text::styles />
now supports a theme
property. It defaults to default
and there's a tweaked richtextlaravel
theme that is intended to work better on Tailwind/Breeze projects.Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.0.0-beta.2...2.0.0-beta.3
Published by tonysm 9 months ago
Full Changelog: https://github.com/tonysm/rich-text-laravel/compare/2.0.0-beta.1...2.0.0-beta.2
If you're upgrading from 1.x, rename all your $richTextFields
properties to $richTextAttributes
instead:
sed -i 's/richTextFields/richTextAttributes/' app/**/*.php
Published by tonysm 9 months ago
<x-rich-text-trix-styles />
to <x-rich-text::styles />
<x-trix-field />
to <x-trix-input />
(only affects new installations)breeze
flag, which makes some tweaks on the default Trix styles so it looks better on Breeze installs (including dark mode), which can be used like <x-rich-text::styles breeze />
Published by tonysm over 1 year ago
Published by tonysm over 1 year ago
Published by tonysm over 2 years ago
richtext:install
command was modified to work with the new Vite setup from Laravel. I also took the time to make it look better. It works with the old Mix installs from Laravel 8 still and, of course, it works when using the Importmap Laravel as well.Published by tonysm over 2 years ago
resources/css/_trix.css
which, based on the app's setup, can do two things: a) automatically add the import line to the resources/css/app.css
file; or b) tell the developer to add the import or do whatever they want with the file<x-rich-text-trix-styles />
Blade Component that can be used to output the Trix core styles (copied from the Trix repository) instead of using a CDN<x-trix-field />
Blade Component is now published to the application's resources/views/components
. This makes for a nice starting point.Published by tonysm over 2 years ago
Published by tonysm over 2 years ago
tonysm/globalid-laravel
package to ^1.1.0
Published by tonysm over 2 years ago
Content::attachables()
method which allows pulling all the attachables of a document right away without having to pluck them out of the attachaments. Previously: $message->content->attachments()->pluck('attachable')
, Now: $message->content->attachables()
. PR: https://github.com/tonysm/rich-text-laravel/pull/20
toHtml(): string
method which allows for easily rendering them. We can now do Attachment::fromAttachable($user)->toHtml()
which renders the <rich-text-attachment>
tag. Same PR as above: https://github.com/tonysm/rich-text-laravel/pull/20
Here's an example of how we can use the Attachment->toHtml()
method to parse the document and create attachments from the backend:
class Message extends Model
{
public static function booted()
{
static::creating(function (Message $message) {
// Scan the document looking for @-mentions and replace them
// with a `<rich-text-attachment>` for the mentioned user...
$message->content = preg_replace_callback(
'/\B\@(\w+)/',
function ($matches) {
if ($user = User::where('username', $matches[1])->first()) {
return Attachment::fromAttachable($user)->toHtml();
}
return $matches[0];
},
$message->content->toHtml(),
);
});
}
}
Published by tonysm almost 3 years ago