如何在laravel应用程序中导入Code ckeditor? [英] How Can i import Code ckeditor in my laravel app?
问题描述
我正在Laravel中创建一个讨论论坛应用程序.在这里,我想在评论部分中使用Ckeditor.当有人发表评论时,代码应该在stackoverflow中显示如下.
I am making a discussion forum application in Laravel . Here I want to use Ckeditor in comment sections. When somebody comments, then the code should show like here in stackoverflow.
@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.请指导我在哪里输入文件和脚本文件.
Please give me very simple steps to use ckeditor. My master file is layout.app and this file is comment.blade.php. Please guide me where I should enter what files and scripts files.
推荐答案
您可以使用laravel CKEditor软件包;
You can use laravel CKEditor Package;
如何安装: 设置包裹
composer require unisharp/laravel-ckeditor
添加ServiceProvider
Add ServiceProvider
编辑config/app.php
,将以下文件添加到Application Service Providers
部分.
Edit config/app.php
, add the following file to Application Service Providers
section.
Unisharp\Ckeditor\ServiceProvider::class,
发布资源
php artisan vendor:publish --tag=ckeditor
用法 默认方式(通过名称或ID初始化):
Usage Default way (initiate by name or id) :
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.replace( 'article-ckeditor' );
</script>
或者如果您想通过jQuery选择器启动:
Or if you want to initiate by jQuery selector :
<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>
示例:
@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>
这篇关于如何在laravel应用程序中导入Code ckeditor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!