How to insert data to database with Laravel
I'm trying to insert my data to database from form.
My URL to create the data is web.com/siswa/create
But when I click submit system show error MethodNotAllowedHttpException.
How I can fix it? Is there anything wrong with my code?
Here is my form:
<form action="{{ url('siswa') }}" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">NISN</label>
<input type="text" class="form-control" name="nisn" id="nisn" placeholder="NISN"></div>
<div class="form-group">
<label for="exampleInputEmail1">Nama Siswa</label>
<input type="text" class="form-control" name="nama_siswa" id="nama_siswa" placeholder="Nama Siswa"> </div>
<button type="submit" class="btn btn-success btn-sm font-weight-bold">Submit</button></form>
Controller:
public function tambah()
{
return view('siswa.create');
}
public function store(Request $request)
{
$siswa = new AppSiswa;
$siswa->nisn = $request->nisn;
$siswa->nama_siswa = $request->nama_siswa;
$siswa->tanggal_lahir = $request->tanggal_lahir;
$siswa->jenis_kelamin = $request->jenis_kelamin;
$siswa->save();
return redirect('siswa');
}
Route:
Route::get('/siswa/create', [
'uses' => 'SiswaController@tambah',
'as' => 'tambah_siswa'
]);
Route::get('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
php laravel laravel-5
add a comment |
I'm trying to insert my data to database from form.
My URL to create the data is web.com/siswa/create
But when I click submit system show error MethodNotAllowedHttpException.
How I can fix it? Is there anything wrong with my code?
Here is my form:
<form action="{{ url('siswa') }}" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">NISN</label>
<input type="text" class="form-control" name="nisn" id="nisn" placeholder="NISN"></div>
<div class="form-group">
<label for="exampleInputEmail1">Nama Siswa</label>
<input type="text" class="form-control" name="nama_siswa" id="nama_siswa" placeholder="Nama Siswa"> </div>
<button type="submit" class="btn btn-success btn-sm font-weight-bold">Submit</button></form>
Controller:
public function tambah()
{
return view('siswa.create');
}
public function store(Request $request)
{
$siswa = new AppSiswa;
$siswa->nisn = $request->nisn;
$siswa->nama_siswa = $request->nama_siswa;
$siswa->tanggal_lahir = $request->tanggal_lahir;
$siswa->jenis_kelamin = $request->jenis_kelamin;
$siswa->save();
return redirect('siswa');
}
Route:
Route::get('/siswa/create', [
'uses' => 'SiswaController@tambah',
'as' => 'tambah_siswa'
]);
Route::get('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
php laravel laravel-5
2
You only haveget
routes but your form is trying toPOST
– Phil
Nov 12 at 4:44
i change it but now system show me error419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
add a comment |
I'm trying to insert my data to database from form.
My URL to create the data is web.com/siswa/create
But when I click submit system show error MethodNotAllowedHttpException.
How I can fix it? Is there anything wrong with my code?
Here is my form:
<form action="{{ url('siswa') }}" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">NISN</label>
<input type="text" class="form-control" name="nisn" id="nisn" placeholder="NISN"></div>
<div class="form-group">
<label for="exampleInputEmail1">Nama Siswa</label>
<input type="text" class="form-control" name="nama_siswa" id="nama_siswa" placeholder="Nama Siswa"> </div>
<button type="submit" class="btn btn-success btn-sm font-weight-bold">Submit</button></form>
Controller:
public function tambah()
{
return view('siswa.create');
}
public function store(Request $request)
{
$siswa = new AppSiswa;
$siswa->nisn = $request->nisn;
$siswa->nama_siswa = $request->nama_siswa;
$siswa->tanggal_lahir = $request->tanggal_lahir;
$siswa->jenis_kelamin = $request->jenis_kelamin;
$siswa->save();
return redirect('siswa');
}
Route:
Route::get('/siswa/create', [
'uses' => 'SiswaController@tambah',
'as' => 'tambah_siswa'
]);
Route::get('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
php laravel laravel-5
I'm trying to insert my data to database from form.
My URL to create the data is web.com/siswa/create
But when I click submit system show error MethodNotAllowedHttpException.
How I can fix it? Is there anything wrong with my code?
Here is my form:
<form action="{{ url('siswa') }}" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">NISN</label>
<input type="text" class="form-control" name="nisn" id="nisn" placeholder="NISN"></div>
<div class="form-group">
<label for="exampleInputEmail1">Nama Siswa</label>
<input type="text" class="form-control" name="nama_siswa" id="nama_siswa" placeholder="Nama Siswa"> </div>
<button type="submit" class="btn btn-success btn-sm font-weight-bold">Submit</button></form>
Controller:
public function tambah()
{
return view('siswa.create');
}
public function store(Request $request)
{
$siswa = new AppSiswa;
$siswa->nisn = $request->nisn;
$siswa->nama_siswa = $request->nama_siswa;
$siswa->tanggal_lahir = $request->tanggal_lahir;
$siswa->jenis_kelamin = $request->jenis_kelamin;
$siswa->save();
return redirect('siswa');
}
Route:
Route::get('/siswa/create', [
'uses' => 'SiswaController@tambah',
'as' => 'tambah_siswa'
]);
Route::get('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
php laravel laravel-5
php laravel laravel-5
edited Nov 12 at 7:28
Mukyuu
6071419
6071419
asked Nov 12 at 4:43
Jazuly
17211
17211
2
You only haveget
routes but your form is trying toPOST
– Phil
Nov 12 at 4:44
i change it but now system show me error419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
add a comment |
2
You only haveget
routes but your form is trying toPOST
– Phil
Nov 12 at 4:44
i change it but now system show me error419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
2
2
You only have
get
routes but your form is trying to POST
– Phil
Nov 12 at 4:44
You only have
get
routes but your form is trying to POST
– Phil
Nov 12 at 4:44
i change it but now system show me error
419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
i change it but now system show me error
419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
add a comment |
5 Answers
5
active
oldest
votes
change your store
function route from get
to post
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
Use Csrf protection field in your form for the session timeout error
{{ csrf_field() }}
OR
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
OR if you are using Form builder
{!! Form::token() !!}
i change it but now system show me error 419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
you need to refresh the form and try again as csrf protection will not allow to refresh the form itself from clickingf5
– Leena Patel
Nov 12 at 4:48
1
yup fix it with add '{{ csrf_field() }}' in the form.
– Jazuly
Nov 12 at 4:49
add a comment |
In Route please use post
instead of get
Route::post('/siswa','SiswaController@store');
and also include {{ csrf_field() }}
in form
add a comment |
you are using method="POST"
on your form but in on your route you are using Route::get
Use Route::post
for your route
add a comment |
In your form you've given POST method, but your router doesn't have any POST handler. So all you have to do is , when you are trying to store data from form to DB you have to post the data, and the router should handle it.
Try this
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
add a comment |
You are using POST method in your form and using GET in route.
try this
Route::post( '/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
] );
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256075%2fhow-to-insert-data-to-database-with-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
change your store
function route from get
to post
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
Use Csrf protection field in your form for the session timeout error
{{ csrf_field() }}
OR
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
OR if you are using Form builder
{!! Form::token() !!}
i change it but now system show me error 419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
you need to refresh the form and try again as csrf protection will not allow to refresh the form itself from clickingf5
– Leena Patel
Nov 12 at 4:48
1
yup fix it with add '{{ csrf_field() }}' in the form.
– Jazuly
Nov 12 at 4:49
add a comment |
change your store
function route from get
to post
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
Use Csrf protection field in your form for the session timeout error
{{ csrf_field() }}
OR
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
OR if you are using Form builder
{!! Form::token() !!}
i change it but now system show me error 419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
you need to refresh the form and try again as csrf protection will not allow to refresh the form itself from clickingf5
– Leena Patel
Nov 12 at 4:48
1
yup fix it with add '{{ csrf_field() }}' in the form.
– Jazuly
Nov 12 at 4:49
add a comment |
change your store
function route from get
to post
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
Use Csrf protection field in your form for the session timeout error
{{ csrf_field() }}
OR
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
OR if you are using Form builder
{!! Form::token() !!}
change your store
function route from get
to post
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
Use Csrf protection field in your form for the session timeout error
{{ csrf_field() }}
OR
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
OR if you are using Form builder
{!! Form::token() !!}
edited Nov 12 at 5:05
answered Nov 12 at 4:47
Leena Patel
1,6151620
1,6151620
i change it but now system show me error 419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
you need to refresh the form and try again as csrf protection will not allow to refresh the form itself from clickingf5
– Leena Patel
Nov 12 at 4:48
1
yup fix it with add '{{ csrf_field() }}' in the form.
– Jazuly
Nov 12 at 4:49
add a comment |
i change it but now system show me error 419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
you need to refresh the form and try again as csrf protection will not allow to refresh the form itself from clickingf5
– Leena Patel
Nov 12 at 4:48
1
yup fix it with add '{{ csrf_field() }}' in the form.
– Jazuly
Nov 12 at 4:49
i change it but now system show me error 419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
i change it but now system show me error 419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47
you need to refresh the form and try again as csrf protection will not allow to refresh the form itself from clicking
f5
– Leena Patel
Nov 12 at 4:48
you need to refresh the form and try again as csrf protection will not allow to refresh the form itself from clicking
f5
– Leena Patel
Nov 12 at 4:48
1
1
yup fix it with add '{{ csrf_field() }}' in the form.
– Jazuly
Nov 12 at 4:49
yup fix it with add '{{ csrf_field() }}' in the form.
– Jazuly
Nov 12 at 4:49
add a comment |
In Route please use post
instead of get
Route::post('/siswa','SiswaController@store');
and also include {{ csrf_field() }}
in form
add a comment |
In Route please use post
instead of get
Route::post('/siswa','SiswaController@store');
and also include {{ csrf_field() }}
in form
add a comment |
In Route please use post
instead of get
Route::post('/siswa','SiswaController@store');
and also include {{ csrf_field() }}
in form
In Route please use post
instead of get
Route::post('/siswa','SiswaController@store');
and also include {{ csrf_field() }}
in form
edited Nov 12 at 5:55
Udhav Sarvaiya
1,20461322
1,20461322
answered Nov 12 at 4:49
raushan kumar
6910
6910
add a comment |
add a comment |
you are using method="POST"
on your form but in on your route you are using Route::get
Use Route::post
for your route
add a comment |
you are using method="POST"
on your form but in on your route you are using Route::get
Use Route::post
for your route
add a comment |
you are using method="POST"
on your form but in on your route you are using Route::get
Use Route::post
for your route
you are using method="POST"
on your form but in on your route you are using Route::get
Use Route::post
for your route
answered Nov 12 at 4:50
Paul Mikki
583
583
add a comment |
add a comment |
In your form you've given POST method, but your router doesn't have any POST handler. So all you have to do is , when you are trying to store data from form to DB you have to post the data, and the router should handle it.
Try this
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
add a comment |
In your form you've given POST method, but your router doesn't have any POST handler. So all you have to do is , when you are trying to store data from form to DB you have to post the data, and the router should handle it.
Try this
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
add a comment |
In your form you've given POST method, but your router doesn't have any POST handler. So all you have to do is , when you are trying to store data from form to DB you have to post the data, and the router should handle it.
Try this
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
In your form you've given POST method, but your router doesn't have any POST handler. So all you have to do is , when you are trying to store data from form to DB you have to post the data, and the router should handle it.
Try this
Route::post('/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
]);
answered Nov 12 at 4:50
Sathiya Seelan D
237
237
add a comment |
add a comment |
You are using POST method in your form and using GET in route.
try this
Route::post( '/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
] );
add a comment |
You are using POST method in your form and using GET in route.
try this
Route::post( '/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
] );
add a comment |
You are using POST method in your form and using GET in route.
try this
Route::post( '/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
] );
You are using POST method in your form and using GET in route.
try this
Route::post( '/siswa', [
'uses' => 'SiswaController@store',
'as' => 'simpan_siswa'
] );
answered Nov 12 at 6:54
Arif Hossain
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256075%2fhow-to-insert-data-to-database-with-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You only have
get
routes but your form is trying toPOST
– Phil
Nov 12 at 4:44
i change it but now system show me error
419 Sorry, your session has expired. Please refresh and try again.
– Jazuly
Nov 12 at 4:47