【问题标题】:Serialization of 'Closure' is not allowed LaravelLaravel 不允许序列化“闭包”
【发布时间】:2020-08-08 15:24:20
【问题描述】:

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

我在 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"
  ]

【问题讨论】:

  • 我不知道它发生在哪里,但该转储显示了一个序列化模型。在文件处理逻辑之前添加一个 dd 以查看它是否也在那里序列化?
  • "noticeTitle" =&gt; "Lorem Ipsum Noticefaafs" "noticeDesc" =&gt; """ &lt;h2&gt;What is Lorem Ipsum?&lt;/h2&gt; &lt;p&gt;&lt;strong&gt;Lorem Ipsum&lt;/strong&gt;&amp;nbsp;is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&amp;#39;s standard dummy text ▶ """ "batch_id" =&gt; "3" ]
  • 我觉得一样...

标签: php laravel


【解决方案1】:

解决了。问题不在迁移时的存储功能中。对于 CKEditor 上的数据,我在迁移时使用了 string。改成text,问题就解决了。

感谢https://stackoverflow.com/a/27003432/10590832 我有个主意。

干杯,

【讨论】:

    猜你喜欢
    • 2014-06-20
    • 1970-01-01
    • 2020-04-06
    • 2018-05-08
    • 2014-04-21
    • 2019-01-30
    • 2017-02-14
    • 2012-11-23
    • 1970-01-01
    相关资源
    最近更新 更多