Skip to content

Commit

Permalink
feat: render blade directive
Browse files Browse the repository at this point in the history
  • Loading branch information
lmottasin committed Oct 3, 2024
1 parent 97a423c commit 3491a5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ php artisan vendor:publish --tag="laravel_editorjs-views"
```

## Usage
Blade Directive
```bladehtml
@render($posts->body)
```

Facade
```php
use App\Models\Post;

Expand Down
11 changes: 11 additions & 0 deletions src/LaravelEditorJsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AlAminFirdows\LaravelEditorJs;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;

class LaravelEditorJsServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -38,5 +39,15 @@ public function boot()
__DIR__ . '/../resources/views' => $this->app->resourcePath('views/vendor/laravel_editorjs'),
], 'laravel_editorjs-views');
}

/**
* Blade directive to render editor.js blocks.
*
* @param mixed $blocks The blocks of content to be rendered.
* @return string Rendered HTML content.
*/
Blade::directive('render', function ($blocks) {
return "<?php echo app('laravel-editorjs')->render($blocks); ?>";
});
}
}

0 comments on commit 3491a5e

Please sign in to comment.