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 bemethod="POST"(missing the equals sign)value"Send"should bevalue="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

