代码之家  ›  专栏  ›  技术社区  ›  risav55

Laravel不允许对'Closure'进行序列化

  •  1
  • risav55  · 技术社区  · 4 年前

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

    我在文本区使用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"
      ]
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   risav55    4 年前

    解决了的。问题不在商店功能范围内,而是在迁移过程中。对于CKEditor上的数据,我使用了 string 关于移民。更改为 text 那么问题就解决了。

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

    干杯,