You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel中CKEditor提交表单无法存储数据至数据库问题排查

Hey there, let's dig into why your form isn't saving data to the database—there are a few small but critical issues in your view code that's causing this:

1. Missing CSRF Token (Laravel's Required Security Measure)

Laravel blocks all POST requests that don't include a CSRF token to prevent cross-site request forgery attacks. Your form doesn't have this token, so the request is getting silently rejected before it even reaches your controller.

Fix: Add @csrf right inside your <form> tag:

<form action="/posting" method="POST">
    @csrf
    <!-- rest of your form fields -->
</form>

2. Syntax Errors in Form Attributes

You've got two typos that break your form's functionality:

  • method "POST" should be method="POST" (missing the equals sign)
  • value"Send" should be value="Send" (missing the equals sign)

Fixed Form Tag & Submit Button:

<form action="/posting" method="POST">
    @csrf
    <!-- ... your form groups ... -->
    <div class="form-group">
        <input type="submit" class="btn btn-primary" value="Send">
    </div>
</form>

3. Typo in Your View Loop

You have a typo in the foreach loop that will cause an error when displaying existing entries: $guestbok->name should be $guestbook->name (missing an 'e').

Fixed Loop:

@foreach ($guestbooks as $guestbook)
<div class="card">
    <div class="card-body">
        <label>mike</label>
        <h3>{{ $guestbook->name }}</h3>
        {!! $guestbook->message !!}
    </div>
</div>
@endforeach

Quick Confirmation

After fixing these issues, test your form again. The CSRF token was the biggest blocker here—without it, Laravel won't process your POST request at all. The syntax errors would have also prevented the form from submitting correctly.

Your Controller and Model code look solid: the $fillable array is correctly configured for mass assignment, and the store method is set up properly to save data.

内容的提问来源于stack exchange,提问作者michael abraham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:50:26