简体   繁体   中英

submit form not storing data to database

So i was trying to make a posting form using ckeditor and post it to database, and then try to display it in the same view, but after i submit the form i don't see anything in my database table so clearly it's not even storing to database, is there any mistakes in my controller or view ?

this is my 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();
    }
}

this is my routes

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

this is my model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

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

and this is my view

<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>

You forgot an equal sign '=' and a csrf field. try the answer.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM