简体   繁体   中英

Can not get my data from my form in Laravel?

I am new to Laravel, I am trying to have a simple example, but I am getting a 419 error, I dont know why it shows up but I will expalin what I did, I created a simple Controller and I called it FormController with the command line :

 php artisan make:controller --resource FormController

In my web.php I added this :

Route::resource('form','FormController');

my view has a simple form in it :

<form action="/form" method="POST" >
   <input type="text" name="cih">
   <input type="submit">
</form>

I open my view with the create method :

public function create()
{
    return view('contact');
}

I want that when I submit my form I get my data, so I use my 'store' method :

public function store(Request $request)
{
    return $request->all();
}

But instead of getting it, I get 419 message, and my session has expired etc ..

I followed a course and that what the teacher was doing I believe nothing more, so I would appreciate any help, I need it.

Thank you

You need to include the CSRF token while submitting a form since the 'VerifyCsrfToken' middleware is enabled by default for the web routes in App/Http/Kernal.php .

<form action="/form" method="POST" >
   @csrf
   <input type="text" name="cih">
   <input type="submit">
</form>

And, Welcome to Laravel!

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