提交不将数据存储到数据库的表单

时间:2019-06-29 04:08:15

标签: php laravel

因此,我试图使用ckeditor制作一个投递表单并将其投递到数据库中,然后尝试以相同的视图显示它,但是提交表单后我在数据库中什么都看不到表如此清晰,甚至没有存储到数据库中,我的控制器或视图中是否有任何错误?

这是我的GuestbookController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Guestbook;

class GuestbookController extends Controller
{
    public function index()
    {
        $guestbooks = Guestbook::get();
        return view('post.post_textarea',[
            'guestbooks' => $guestbooks,
        ]);
    }

    public function store(Request $request)
    {
        Guestbook::create([
            'name' => $request->name,
            'message' => $request->message
        ]);
        return redirect()->back();
    }
}

这是我的路线

Route::get('/posting','GuestbookController@index')->name('guestbook');
Route::post('/posting','GuestbookController@store')->name('guestbook.store');

这是我的模特

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Guestbook extends Model
{
    protected $fillable = ['name', 'message'];
}

这是我的观点

<section class="games-single-page">
        <div class="container">
            @foreach ($guestbooks as $guestbook)
            <div class="card">
                <div class="card-body">
                    <label>mike</label>
                    <h3>{{ $guestbok->name }}</h3>
                    {!! $guestbook->message !!}
                </div>
            </div>
            @endforeach
            <div class="card">
                <div class="card-body">
                    <form action="/posting" method "POST">
                        <div class="form-group">
                            <label style="color: black;" >Title</label>
                            <input type="text" class="form-control" name="name">
                        </div>
                        <div class="form-group">
                            <label style="color: black;" >Your Input</label>
                            <br>
                                <textarea class="form-control" name="message" id="" rows="10"></textarea>
                        </div>
                        <div class="form-group">
                            <input type="submit" class="btn btn-primary" value"Send">  
                        </div>                     
                    </form>
                </div>
            </div>
        </div>
    </section>

1 个答案:

答案 0 :(得分:1)

您忘记了等号'='和一个csrf字段。尝试答案。

<form action="/posting" method="POST">
{{csrf_field()}}