I am coding a comment section; i am getting user data from the form below:
<div class="comment">
<h2>Leave a comment</h2>
<form method="post" action="/blog/{{$post->id}}/comments">
{{csrf_field()}}
<input type="text" name= "name" class="textbox" value="Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}">
<input type="text" name="email" class="textbox" value="Email" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}">
<textarea value="Message:" name="body" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message';}">Message</textarea>
<div class="smt1">
<input type="submit" value="add a comment">
</div>
</form>
</div>
I am getting those data on a route via CommentsController store method like below:
Route::post('/blog/{post}/comments','CommentsController@store');
Then storing them on db via controller's method: `
public function store(Post $post){
Comment::create([
'body' => request('body'),
'email' =>request('email'),
'name' =>request('name'),
'post_id' => $post->id
]);
return back();
}
the issue is that when I go on the database the body field gets inserted totally fine, but post_id, name, email they dont get inserted on databse, they are empty.
I have checked if I am getting the data from the form I have done die; dump dd(); on name, email and $post->id I get the data totally fine from the form, but I can not get them inserted on the database?