2

Error: "Serialization of Closure is not allowed" while storing the data.

I am using CKEditor on textarea. Data is stored when there is not more text but when there is more text like the first question and it's answered on https://www.lipsum.com then it shows error while saving the data.

Store Function

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');
    }
}

dump of $notice variable goes as

"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"
  ]
3
  • I don't know where it's happening but that dump shows a serialized model. Add a dd before file handling logic to see if its serialized there as well?
    – Avi
    Aug 8, 2020 at 6:23
  • "noticeTitle" => "Lorem Ipsum Noticefaafs" "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" ]
    – risav55
    Aug 8, 2020 at 6:54
  • I think its same...
    – risav55
    Aug 8, 2020 at 6:55

1 Answer 1

0

Solved. The problem wasn't within the store function it's on migration. For data on CKEditor, I was using a string on migration. Changed it to text then problem solved.

All thanks to https://stackoverflow.com/a/27003432/10590832 I got an idea.

Cheers,

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.