Postingan lainnya
tambah data menggunakan laravel 11
saya sudah mengotak atik nya menggunakan berbagai metode tapi masi belum berhasil,sudah saya coba menggunakan query builder tapi hasilnya nihil berikut controller nya :
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Instalasi;
use App\Models\DPInstalasi; // Impor model DPInstalasi
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;
class InstalasiController extends Controller
{
public function instalasi()
{
// Mengambil data instalasi dari database
$instalasi = DB::table('instalasi')->select('id_instalasi', 'nama_cs', 'alamat', 'tanggal')->get();
// Mengirim data ke view
return view('admin.instalasi', ['instalasi' => $instalasi]);
}
public function tambah()
{
// Menampilkan formulir instalasi
return view('admin.form_instalasi');
}
public function simpan(Request $request)
{
// Log data request untuk debugging
Log::info('Request Data:', $request->all());
// Validasi data form
$validatedData = $request->validate([
'no_iwo' => 'required',
'id_cs' => 'required',
'nama_cs' => 'required',
'tanggal' => 'required|date',
'alamat' => 'required',
'kota' => 'required',
'kode_pos' => 'required',
'jenis_layanan' => 'required',
'bandwidth_intl_ix' => 'required',
'bandwidth_lokal_iix' => 'required',
'jumlah_rak' => 'required',
'no_rak' => 'required',
'block_ip_wan_cs' => 'required',
'block_ip_lan' => 'required',
'gateway_ip' => 'required',
'primary_dns' => 'required',
'secondary_dns' => 'required',
'detail_pekerjaan' => 'required',
'ping' => 'required',
'trace_route' => 'required',
'browsing' => 'required',
'download' => 'required',
'speed' => 'required',
'nama_teknisi' => 'required',
'nama_cs_ttd' => 'required',
'ttd_teknisi' => 'required',
'ttd_cs' => 'required',
'dp_instalasi.*.nama_perangkat' => 'required',
'dp_instalasi.*.merk' => 'required',
'dp_instalasi.*.nomor_seri' => 'required',
'dp_instalasi.*.jumlah' => 'required|integer',
'dp_instalasi.*.satuan' => 'required',
]);
// Simpan data tanda tangan
$teknisiSignature = $this->saveSignature($request->input('ttd_teknisi'), 'ttd_teknisi');
$customerSignature = $this->saveSignature($request->input('ttd_cs'), 'ttd_cs');
// Simpan data instalasi
$instalasi = Instalasi::create([
'no_iwo' => $validatedData['no_iwo'],
'id_cs' => $validatedData['id_cs'],
'nama_cs' => $validatedData['nama_cs'],
'tanggal' => $validatedData['tanggal'],
'alamat' => $validatedData['alamat'],
'kota' => $validatedData['kota'],
'kode_pos' => $validatedData['kode_pos'],
'jenis_layanan' => $validatedData['jenis_layanan'],
'bandwidth_intl_ix' => $validatedData['bandwidth_intl_ix'],
'bandwidth_lokal_iix' => $validatedData['bandwidth_lokal_iix'],
'jumlah_rak' => $validatedData['jumlah_rak'],
'no_rak' => $validatedData['no_rak'],
'block_ip_wan_cs' => $validatedData['block_ip_wan_cs'],
'block_ip_lan' => $validatedData['block_ip_lan'],
'gateway_ip' => $validatedData['gateway_ip'],
'primary_dns' => $validatedData['primary_dns'],
'secondary_dns' => $validatedData['secondary_dns'],
'detail_pekerjaan' => $validatedData['detail_pekerjaan'],
'ping' => $validatedData['ping'],
'trace_route' => $validatedData['trace_route'],
'browsing' => $validatedData['browsing'],
'download' => $validatedData['download'],
'speed' => $validatedData['speed'],
'nama_teknisi' => $validatedData['nama_teknisi'],
'nama_cs_ttd' => $validatedData['nama_cs_ttd'],
'ttd_teknisi' => $teknisiSignature,
'ttd_cs' => $customerSignature,
]);
// Log data instalasi untuk debugging
Log::info('Instalasi Data:', $instalasi->toArray());
// Simpan data perangkat ke tabel dp_instalasi
foreach ($request->dp_instalasi as $item) {
Log::info('DP Instalasi Item:', $item);
$instalasi->dpInstalasi()->create([
'id_instalasi' => $instalasi->id_instalasi,
'nama_perangkat' => $item['nama_perangkat'],
'merk' => $item['merk'],
'nomor_seri' => $item['nomor_seri'],
'jumlah' => $item['jumlah'],
'satuan' => $item['satuan'],
'keterangan' => $item['keterangan'] ?? null,
]);
}
return redirect()->route('admin.instalasi')->with('success', 'Data berhasil disimpan!');
}
private function saveSignature($signatureData, $filename)
{
$folderPath = "signatures/";
$image_parts = explode(";base64,", $signatureData);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$fileName = $folderPath . uniqid() . '.' . $image_type;
Storage::disk('public/images')->put($fileName, $image_base64);
return $fileName;
}
public function hapus($id)
{
try {
// Cari data instalasi berdasarkan id
$instalasi = Instalasi::findOrFail($id);
// Hapus data detail perangkat instalasi terkait
$instalasi->dpInstalasi()->delete();
// Hapus data instalasi
$instalasi->delete();
// Redirect dengan pesan sukses
return redirect()->route('admin.instalasi')->with('success', 'Data berhasil dihapus!');
} catch (\Exception $e) {
// Tangani kesalahan jika terjadi
return redirect()->route('admin.instalasi')->with('error', 'Terjadi kesalahan saat menghapus data: ' . $e->getMessage());
}
}
}
berikut model nya
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DPInstalasi extends Model
{
use HasFactory;
protected $table = 'dp_instalasi';
protected $primaryKey = 'id_dp_instalasi';
protected $fillable = [
'id_instalasi', 'nama_perangkat', 'merk', 'nomor_seri', 'jumlah', 'satuan', 'keterangan'
];
// Relasi ke Instalasi
public function instalasi()
{
return $this->belongsTo(Instalasi::class, 'id_instalasi', 'id_instalasi');
}
}
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model;
class Instalasi extends Model { use HasFactory;
protected $table = 'instalasi';
protected $primaryKey = 'id_instalasi';
protected $fillable = [
'no_iwo', 'customer_id', 'nama_cs', 'tanggal', 'alamat', 'kode_pos', 'kota',
'jenis_layanan', 'bandwidth_intl_ix', 'bandwidth_lokal_iix', 'jumlah_rak',
'no_rak', 'block_ip_wan_cs', 'block_ip_lan', 'gateway_ip', 'primary_dns',
'secondary_dns', 'detail_pekerjaan', 'ping', 'trace_route', 'browsing',
'download', 'speed', 'ttd_teknisi', 'nama_teknisi', 'ttd_cs', 'nama_cs_ttd'
];
// Relasi ke DPInstalasi (Detail Perangkat Instalasi)
public function dpInstalasi()
{
return $this->hasMany(DPInstalasi::class, 'id_instalasi', 'id_instalasi');
}
}
berikut view nya
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Berita Acara Instalasi</title>
<link rel="stylesheet" href="{{ asset('css/form-instalasi.css') }}">
</head>
<body>
<form action="{{ route('admin.instalasi.simpan') }}" id="id_form_instalasi" method="POST" enctype="multipart/form-data">
@csrf
<div class="header-container">
<div class="top-section">
<div class="left-section">
<div class="logo-container">
<img class="logo" src="{{ asset('images/indonet.png') }}" alt="Indonet Logo">
<img class="logo" src="{{ asset('images/kan.png') }}" alt="Kan Logo">
<img class="logo" src="{{ asset('images/materai.png') }}" alt="Materai Logo">
</div>
<div class="company-info">
<p>PT. Indointernet Tbk</p>
<p>Rumah Indonet</p>
<p>Jl. Rempoa Raya no. 11, Tangerang 15412, Indonesia</p>
<p>T. +62 21 7388-2525 | T. Support +62 21 2755-5222</p>
<p>F. +62 21 7388-2626 | Website: <a href="http://www.indo.net.id">www.indo.net.id</a></p>
<p>E-mail: <a href="mailto:support@indonet.co.id">support@indonet.co.id</a></p>
</div>
</div>
<div class="details">
<div class="info-item">
<label for="no_iwo">No IWO:
<input type="text" id="no_iwo" name="no_iwo" value="{{ old('no_iwo') }}" required placeholder="Masukkan No IWO">
</label>
</div>
<div class="info-item">
<label for="id_cs">Customer ID:
<input type="text" id="id_cs" name="id_cs" value="{{ old('id_cs') }}" required placeholder="Masukkan Customer ID">
</label>
</div>
</div>
</div>
<div class="title-container">
<strong>
<div class="line"></div>
<div class="title">BERITA ACARA INSTALASI DAN AKTIVASI</div>
<em>STATEMENT OF ACCEPTANCE</em>
</strong>
</div>
<div class="content-container">
<p class="content-text">
Dengan ini, kedua belah pihak, yakni PT. Indointernet Tbk sebagai Penyedia Layanan dan
</p>
<p class="content-text">
<label for="nama_cs"></label>
<input type="text" id="nama_cs" name="nama_cs" class="no-border" value="{{ old('nama_cs') }}" required placeholder="Nama Customer">
Sebagai Customer Pada:
</p>
</div>
<div class="content-container">
<p class="content-text1">
<label class="input-container" for="tanggal">
Hari, Tanggal:
<input type="date" id="tanggal" name="tanggal" value="{{ old('tanggal') }}">
</label>
</p>
<p class="content-text1">
mengetahui bahwa telah dilakukan instalasi perangkat pada lokasi Customer yang bertempatkan di:
</p>
<div class="address-container">
<div class="address-column">
<div class="address-item">
<label for="alamat">Alamat:</label>
<textarea id="alamat" name="alamat" value="{{ old('alamat') }}"></textarea>
</div>
</div>
<div class="address-column">
<div class="address-item">
<label for="kode_pos">Kode Pos:</label>
<input type="text" id="kode_pos" name="kode_pos" value="{{ old('kode_pos') }}">
</div>
<div class="address-item">
<label for="kota">Kota/Kabupaten:</label>
<input type="text" id="kota" name="kota" value="{{ old('kota') }}">
</div>
</div>
</div>
<p class="content-text">
dengan rincian sebagai berikut:
</p>
<div class="service-table-container">
<div class="service-table">
<div class="service-column">
<div class="service-row">
<label for="jenis_layanan">Jenis Layanan:</label>
<input type="text" id="jenis_layanan" name="jenis_layanan" value="{{ old('jenis_layanan') }}">
</div>
<div class="service-row">
<label for="bandwidth_intl">Bandwidth Intl. (XI):
<input type="text" id="bandwidth_intl_ix" name="bandwidth_intl_ix" value="{{ old('bandwidth_intl_ix') }}">
</label>
</div>
<div class="service-row">
<label for="bandwidth_local">Bandwidth Lokal (XI):
<input type="text" id="bandwidth_lokal_iix" name="bandwidth_lokal_iix" value="{{ old('bandwidth_lokal_iix') }}">
</label>
</div>
<div class="rack-row">
<label for="jumlah_rak">Jumlah Rak:</label>
<input type="text" id="jumlah_rak" name="jumlah_rak" value="{{ old('jumlah_rak') }}">
<label for="no_rak">No. Rak:</label>
<input type="text" id="no_rak" name="no_rak" value="{{ old('no_rak') }}">
</div>
</div>
<div class="vertical-line"></div>
<div class="service-column">
<div class="service-row">
<label for="block_ip_wan">Block IP WAN Customer:
<input type="text" id="block_ip_wan_cs" name="block_ip_wan_cs" value="{{ old('block_ip_wan_cs') }}">
</label>
</div>
<div class="service-row">
<label for="block_ip_lan">Block IP LAN Customer:
<input type="text" id="block_ip_lan_cs" name="block_ip_lan" value="{{ old('block_ip_lan_cs') }}">
</label>
</div>
<div class="service-row">
<label for="gateway_ip">Gateway IP:</label>
<div class="ip-blocks">
<input type="text" id="gateway_ip" name="gateway_ip" value="{{ old('gateway_ip') }}">
</div>
</div>
<div class="service-row">
<label for="primary_dns">Primary DNS:</label>
<div class="ip-blocks">
<input type="text" id="primary_dns" name="primary_dns" value="{{ old('primary_dns') }}">
</div>
</div>
<div class="service-row">
<label for="secondary_dns">Secondary DNS:</label>
<div class="ip-blocks">
<input type="text" id="secondary_dns" name="secondary_dns" value="{{ old('secondary_dns') }}">
</div>
</div>
</div>
</div>
<div class="job-details-container">
<div class="job-details">
<label for="detail_pekerjaan">Detail pekerjaan:</label>
<label for="pemasangan">
<input type="radio" id="pemasangan" name="detail_pekerjaan" value="pemasangan">
Pemasangan
</label>
<label for="peningkatan">
<input type="radio" id="peningkatan" name="detail_pekerjaan" value="peningkatan">
Peningkatan
</label>
<label for="penurunan">
<input type="radio" id="penurunan" name="detail_pekerjaan" value="penurunan">
Penurunan
</label>
<label for="pemindahan">
<input type="radio" id="pemindahan" name="detail_pekerjaan" value="pemindahan">
Pemindahan
</label>
<label for="penggantian">
<input type="radio" id="penggantian" name="detail_pekerjaan" value="penggantian">
Penggantian
</label>
</div>
</div>
</div>
<p class="agreement-text">
HASIL UJI AKTIVASI
</p>
<div class="activation-result-container">
<div class="job-details">
<label>
<input type="checkbox" id="ping" name="ping" value="ping" {{ old('ping') ? 'checked' : '' }}>
Ping
</label>
<label>
<input type="checkbox" id="trace_route" name="trace_route" value="trace_route" {{ old('trace_route') ? 'checked' : '' }}>
Trace Route
</label>
<label>
<input type="checkbox" id="browsing" name="browsing" value="browsing" {{ old('browsing') ? 'checked' : '' }}>
Browsing
</label>
<label>
<input type="checkbox" id="download" name="download" value="download" {{ old('download') ? 'checked' : '' }}>
Download
</label>
<div class="speed-item">
<label for="speed">Speed:</label>
<input type="text" id="speed" name="speed" value="{{ old('speed') }}">
<span>Mbps</span>
</div>
</div>
</div>
<h3>Data Perangkat Milik Indonet :</h3>
<table class="custom-table" id="dpInstalasiTable">
<thead>
<tr>
<th class="custom-th">Nomor</th>
<th class="custom-th">Nama Perangkat</th>
<th class="custom-th">Merek</th>
<th class="custom-th">Nomor Seri</th>
<th class="custom-th">Jumlah</th>
<th class="custom-th">Satuan</th>
<th class="custom-th">Keterangan</th>
<th class="custom-th">Aksi</th>
</tr>
</thead>
<tbody>
<tr>
<td class="custom-td">1</td>
<td class="custom-td">
<label for="nama_perangkat_0" class="sr-only">Nama Perangkat</label>
<input type="text" id="nama_perangkat_0" name="dp_instalasi[0][nama_perangkat]" class="custom-input-text" value="{{ old('dp_instalasi[0][nama_perangkat]') }}" required />
</td>
<td class="custom-td">
<label for="merk_0" class="sr-only">Merek</label>
<input type="text" id="merk_0" name="dp_instalasi[0][merk]" class="custom-input-text" value="{{ old('dp_instalasi[0][merk]') }}" required/>
</td>
<td class="custom-td">
<label for="nomor_seri_0" class="sr-only">Nomor Seri</label>
<input type="text" id="nomor_seri_0" name="dp_instalasi[0][nomor_seri]" class="custom-input-text" value="{{ old('dp_instalasi[0][nomor_seri]') }}" required/>
</td>
<td class="custom-td">
<label for="jumlah_0" class="sr-only">Jumlah</label>
<input type="number" id="jumlah_0" name="dp_instalasi[0][jumlah]" class="custom-input-number" value="{{ old('dp_instalasi[0][jumlah]') }}" />
</td>
<td class="custom-td">
<label for="satuan_0" class="sr-only">Satuan</label>
<input type="text" id="satuan_0" name="dp_instalasi[0][satuan]" class="custom-input-text" value="{{ old('dp_instalasi[0][satuan]') }}" />
</td>
<td class="custom-td">
<label for="keterangan_0" class="sr-only">Keterangan</label>
<input type="text" id="keterangan_0" name="dp_instalasi[0][keterangan]" class="custom-input-text" value="{{ old('dp_instalasi[0][keterangan]') }}" />
</td>
<td>
<button type="button" onclick="removeRow(this)">Hapus</button>
</td>
</tr>
</tbody>
</table>
<button type="button" onclick="addRow()">Tambah Baris</button>
<!-- Signature Section -->
<div class="signature-container" style="display: flex; justify-content: space-between;">
<!-- Left Signature -->
<div>
<div class="signature-title">PT. Indonet,</div>
<div class="signature-box" id="left-signature-box">
<input type="hidden" id="left_signature" name="ttd_teknisi">
<canvas id="left-signature-canvas" style="width: 100%; height: 100%;"></canvas>
<button type="button" class="clear-button" onclick="clearSignature('left-signature-canvas')">Clear</button>
</div>
<div class="signature-label">Teknisi</div>
<input type="text" class="custom-input-text" style="width: 100%;" placeholder="Nama Teknisi" required>
</div>
<!-- Right Signature -->
<div>
<div class="signature-title">Customer,</div>
<div class="signature-box" id="right-signature-box">
<input type="hidden" id="right_signature" name="ttd_cs">
<canvas id="right-signature-canvas" style="width: 100%; height: 100%;"></canvas>
<button type="button" class="clear-button" onclick="clearSignature('right-signature-canvas')">Clear</button>
</div>
<div class="signature-label">Customer</div>
<input type="text" class="custom-input-text" style="width: 100%;" placeholder="Nama Customer" required>
</div>
</div>
<button type="submit" onclick="saveSignatures()">Simpan Data</button>
</div>
</div>
</form>
<script src="{{ asset('js/form-instalasi.js') }}"></script>
</body>
</html>
dan berikut route nya
//Instalasi (admin)
Route::prefix('admin')->group(function () {
Route::get('/instalasi', [InstalasiController::class, 'instalasi'])->name('admin.instalasi');
Route::get('/instalasi/tambah', [InstalasiController::class, 'tambah'])->name('admin.form_instalasi');
Route::post('/instalasi/simpan', [InstalasiController::class, 'simpan'])->name('admin.instalasi.simpan');
});
0
1 Jawaban:
sebelum simpan coba di dd dulu
dd([
'no_iwo' => $validatedData['no_iwo'],
'id_cs' => $validatedData['id_cs'],
'nama_cs' => $validatedData['nama_cs'],
'tanggal' => $validatedData['tanggal'],
'alamat' => $validatedData['alamat'],
'kota' => $validatedData['kota'],
'kode_pos' => $validatedData['kode_pos'],
'jenis_layanan' => $validatedData['jenis_layanan'],
'bandwidth_intl_ix' => $validatedData['bandwidth_intl_ix'],
'bandwidth_lokal_iix' => $validatedData['bandwidth_lokal_iix'],
'jumlah_rak' => $validatedData['jumlah_rak'],
'no_rak' => $validatedData['no_rak'],
'block_ip_wan_cs' => $validatedData['block_ip_wan_cs'],
'block_ip_lan' => $validatedData['block_ip_lan'],
'gateway_ip' => $validatedData['gateway_ip'],
'primary_dns' => $validatedData['primary_dns'],
'secondary_dns' => $validatedData['secondary_dns'],
'detail_pekerjaan' => $validatedData['detail_pekerjaan'],
'ping' => $validatedData['ping'],
'trace_route' => $validatedData['trace_route'],
'browsing' => $validatedData['browsing'],
'download' => $validatedData['download'],
'speed' => $validatedData['speed'],
'nama_teknisi' => $validatedData['nama_teknisi'],
'nama_cs_ttd' => $validatedData['nama_cs_ttd'],
'ttd_teknisi' => $teknisiSignature,
'ttd_cs' => $customerSignature]
]);
sudah masuk semua blum data nya
0