rur2641 rur2641 - 2 months ago 16
PHP Question

How to post to a database from a form

How to post the contents of a form to db? I know the database works.

<form method="post" action="{{ action('UserController@registration') }}">
<h1>Please Name</h1>
<textarea name="name"></textarea>
<button type="submit">Access</button>
</form>

Route::post('/registration', 'UserController@registration');

public function registration(Request $request)
{
DB::table(‘user2s’)->insert([‘name’=> $request->name]);
return 'success';
}

Answer

Add this token in your form

{!! Form::token() !!}

or this

<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />