can someone help me...my laravel code insert twice to database when I click submit, it store double data to database, here is my code : controller
public function store(Request $request)
{
$this ->validate($request,[
'nim' => 'required|max:8',
'nama' => 'required|max:30',
'alamat' => 'required|max:100',
'jenis_kelamin' => 'required|max:9',
'no_tlp' => 'required|regex:/[0-9]{12}/',
'tempat' => 'required',
'tanggal' => 'required',
'id_jurusan' => 'required'
]);
$simpan = new Mahasiswa([
'nim' => $request->get('nim'),
'nama' => $request->get('nama'),
'alamat' => $request->get('alamat'),
'jenis_kelamin' => $request->get('jenis_kelamin'),
'no_tlp' => $request->get('no_tlp'),
'tempat' => $request->get('tempat'),
'tanggal' => $request->get('tanggal'),
'id_jurusan' => $request->get('id_jurusan')
]);
$simpan->save();
if (Mahasiswa::create($request->all())) {
$request->session()->flash('status', 'success');
$request->session()->flash('pesan', 'Data Berhasil Disimpan');
}else{
$request->session()->flash('status', 'danger');
$request->session()->flash('pesan', 'Data gagal Disimpan!!');
}
return redirect('/Mahasiswa/create');
}
and this my model code :
class Mahasiswa extends Model
{
protected $fillable = ['nim','nama','alamat','jenis_kelamin','no_tlp','tempat','tanggal','id_jurusan'];
protected $table = 'mahasiswa';
}
Thanks before...
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire