Laravel ckeditor数据不能插入数据库

Laravel ckeditor data doesn't insert in database

本文关键字:插入 数据库 不能 数据 ckeditor Laravel      更新时间:2023-09-26

我使用的是Laravel 5.2,并使用UniSharp/Laravel -ckeditor包在我的项目中实现ckeditor。一切似乎都很顺利。但当我发送ckeditor输入字段的数据时,它并没有插入数据库。其他输入字段的数据工作正常。当我使用普通文本区域而不是ckeditor时,它也工作得很好。

在我看来:
 {{Form::open(array('url'=>'gettopics'))}}
            <input type="text" name="title" class="form-control"/>
           **<input type="textarea" name="detail" id="article-ckeditor">**
    {{Form::close()}}

<script>
        CKEDITOR.replace( 'article-ckeditor' );
    </script>

的路线:

Route::post('gettopics','TopicsController@gettopics');

控制器:

public function gettopics(Request $request){
    $topic=new Topic;
$topic->title=$request->Input('title');
$topic->detail=$request->Input('detail');
 $topic->save();
}

要呈现html内容,请执行以下操作

{{!! $topic->detail !!}}

注意,如果空格错误,它将不起作用。因此,请确保在第一个'!! !后",没有空间最后的! !"。

Textarea作为HTML标签插入错误。你应该这样修改你的代码:

My Editor:<br>
            <textarea name="article-ckeditor" id="article-ckeditor">&lt;p&gt;Initial editor content.&lt;/p&gt;</textarea>
            <script>
                CKEDITOR.replace( 'article-ckeditor' );
            </script>

同样在你的控制器中,没有叫做Input的函数,它是Input。修改你的控制器如下:

public function gettopics(Request $request){
    $topic=new Topic;
    $topic->title=$request->input('title');
    $topic->detail=$request->input('detail');
    $topic->save();
}