Page 13 - Modul CRUD Laravel_Neat
P. 13
<td><input type="text" name="harga" class="form-
control" required="required"></td>
</tr>
<tr>
<td><input type="submit" class="btn btn-info mt-
3" class="form-control" value="Simpan Data"></td>
<td><a href="/barang" class="btn btn-danger mt-
3" role="button">Kembali</a></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
20. Kemudian tambahkan fungsi pada controller barang.
public function viewAdd()
{
return view('barang_add');
}
public function actionAdd(Request $request)
{
DB::table('barang')->insert([
'nama_barang' => $request->nama,
'jumlah_barang' => $request->jumlah,
'harga_barang' => $request->harga
]);
return redirect('/barang');
}
Dan juga routing
Route::get('/barang/add', [BarangController::class, 'viewAdd']);
Route::post('/barang/action-
add', [BarangController::class, 'actionAdd']);