如何在我的 laravel 应用程序中导入 Code ckeditor?

How Can i import Code ckeditor in my laravel app?

我正在 Laravel 中制作论坛应用程序。这里我想在评论区使用Ckeditor。当有人发表评论时,代码应该在 Whosebug 中显示为此处。

@if(Auth::check()!=null)
    <div class="col-md-6 col-md-offset-3">
        <div class="panel panel-default">
            <div class="panel panel-body">
                <form action="/comment" method="POST">
                    {{ csrf_field() }}
                    <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
                    <input type="hidden" name="post_id" value="{{ $post->id }}">
                    <div class="form-group">
                        <label for="comment">Reply</label>
                        <textarea name="body" class="form-control" style="size: 200px"></textarea>
                    </div>
                    <input type="submit" name="com" id="com"  class="btn btn-xs btn-success pull-right">
                </form>
            </div>
        </div>
    </div>
@endif

请给我使用ckeditor的非常简单的步骤。我的主文件是 layout.app,这个文件是 comment.blade.php。请指导我应该在哪里输入什么文件和脚本文件。

您可以使用 laravel CKEditor 包;

如何安装: 设置包

composer require unisharp/laravel-ckeditor

添加服务提供商

编辑 config/app.php,将以下文件添加到 Application Service Providers 部分。

Unisharp\Ckeditor\ServiceProvider::class,

发布资源

php artisan vendor:publish --tag=ckeditor

用法 默认方式(通过名称或id启动):

<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
    CKEDITOR.replace( 'article-ckeditor' );
</script>

或者如果您想通过 jQuery 选择器启动:

<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script src="/vendor/unisharp/laravel-ckeditor/adapters/jquery.js"></script>
<script>
    $('textarea').ckeditor();
    // $('.textarea').ckeditor(); // if class is prefered.
</script>

github link for more

示例:

@if(Auth::check()!=null)
<div class="col-md-6 col-md-offset-3">
    <div class="panel panel-default">
        <div class="panel panel-body">
            <form action="/comment" method="POST">
                {{ csrf_field() }}
                <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
                <input type="hidden" name="post_id" value="{{ $post->id }}">
                <div class="form-group">
                    <label for="comment">Reply</label>
                    <textarea id="editor1" name="body" class="form-control" style="size: 200px"></textarea>
                </div>
                <input type="submit" name="com" id="com"  class="btn btn-xs btn-success pull-right">
            </form>
        </div>
    </div>
</div>
@endif

<script>

    $('.editor1').ckeditor(); // if class is prefered.
</script>
    <script src="{{asset('vendor/unisharp/laravel-ckeditor/ckeditor.js')}}"></script>
    <script src="{{asset('vendor/unisharp/laravel-ckeditor/adapters/jquery.js')}}"></script>

@section('script')

    <script>

        $('textarea').ckeditor();
    </script>

    @endsection

并且我提供了编辑器 ID