Laravel不允许序列化“关闭”

时间:2020-08-08 06:10:01

标签: php laravel

错误:存储数据时出现“不允许序列化闭包”。

我在textarea上使用CKEditor。当没有更多的文本但有更多的文本(如第一个问题)并且在https://www.lipsum.com上回答了数据时,将存储数据。

存储功能

public function store(Request $request)
{
    $this->validate($request, [
        'noticeTitle'        => 'required',
        'noticeDesc'       => 'required',
    ]);

    $notice = new Notice;
    $notice->noticeTitle = $request->input('noticeTitle');
    $notice->noticeDesc = $request->input('noticeDesc');

    $notice->batch_id = $request->input('targetedGroup');


    if($request->hasFile('add_file')) {
        $noticeTitle = $request->input('noticeTitle');

        $filename  = $request->add_file->getClientOriginalName();

        $request->add_file->storeAs('public/noticeFile/additionalFiles', $noticeTitle.'_'.$filename);
        $path = $noticeTitle.'_'.$filename;

        $notice->file = $path;
    }
    dd($notice);
    try{
        $notice->save();
        Session::flash('success', 'Notice Saved');
        return redirect()->route('notice.index');
    }
    catch (\Throwable $th){
        Session::flash('danger', $th);
        return redirect()->route('notice.index');
    }
}

$ notice变量的转储为

"noticeTitle" => "Lorem Ipsum Notice New"
    "noticeDesc" => """
      <h2>What is Lorem Ipsum?</h2>
      
      <p><strong>Lorem Ipsum</strong>&nbsp;is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#39;s standard dummy text  ▶
      """
    "batch_id" => "3"
    "file" => "Lorem Ipsum Notice New_s.pdf"
  ]

1 个答案:

答案 0 :(得分:0)

已解决。问题不在于存储功能,而在于迁移。对于CKEditor上的数据,我在迁移时使用了string。将其更改为text,然后问题解决了。

感谢Heroku 我有个主意。

干杯