英文:
Laravel ["message": "Too few arguments to function App\\Http\\Controllers\\BursaPembelianController::edit_bursa_pembelian(), 1 passed in
问题
抱歉,以下是您要求的翻译:
您好,我想问你一些问题,我在我的Laravel项目中遇到了问题,我总是看到错误消息:"message": "App\\\\Http\\\\Controllers\\\\BursaPembelianController::edit_bursa_pembelian()的参数太少..."
请给我提供解决错误消息的解决方案,下面我提供了我创建的源代码视图。
视图:
@extends('layouts.main')
@section('container')
<body class="InvPinjam()">
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
<h4 class="mb-sm-0 font-size-18">{{ $label }}</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item">{{ ucwords($menu) }}</li>
<li class="breadcrumb-item">{{ ucwords($submenu) }}</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Kode Pembelian <code>*</code></label>
<input type="disable" class="form-control" id="kode_transaksi"
name="kode_transaksi" value="{{ $pembelian->kode_transaksi }}" disabled>
<input type="hidden" name="purchase_id" id="purchase_id"
value="{{ $pembelian->id }}">
<input type="hidden" name="url" id="url"
value="{{ Crypt::encryptString($pembelian->kode_transaksi) }}">
</div>
</div>
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Tanggal <code>*</code></label>
<input type="disable" class="form-control" name="tgl_kedatangan"
id="tgl_kedatangan" value="{{ $pembelian->tgl_kedatangan }}" readonly>
<input type="disable" class="form-control" name="id_peminjam" id="id_peminjam"
value="" hidden>
{!! $errors->first('nama_peminjam', '<div class="invalid-validasi">:message</div>') !!}
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Supplier </label>
<div class="input-group">
<input type="text" class="form-control" name="supplier" id="supplier"
value="{{ $pembelian->id_supplier }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
{!! $errors->first('tgl_permintaan', '<div class="invalid-validasi">:message</div>') !!}
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Surat Jalan </label>
<div class="input-group">
<input type="text" class="form-control" name="suratjalan" id="suratjalan"
value="{{ $pembelian->nomor_do }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Status Pembayaran </label>
<div class="input-group">
<input type="text" class="form-control" name="pembayaran" id="pembayaran"
value="{{ $pembelian->status_pembayaran }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Potongan </label>
<div class="input-group">
<input type="text" class="form-control" name="potongan" id="potongan"
value="{{ $pembelian->potongan }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
</div>
</div>
</div>
{{-- keterengan --}}
<div class="row">
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Ongkir <code>*</code></label>
<input type="disable" class="form-control" id="kode_transaksi"
name="kode_transaksi" value="{{ $pembelian->ongkir ?? 0 }}">
</div>
</div>
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Keterangan <code>*</code></label>
<textarea id="keterangan" class="form-control" name="keterangan"
style="height: 50px;" placeholder="Keterangan"></textarea>
</div>
</div>
</div>
</div>
{{-- //keterangan --}}
<div class="row">
<div class="col-md-12 table-responsive">
<table class="table table-responsive table-bordered table-striped" id="tableList">
<thead>
<tr>
<th class="text-center" style="width: 5%">No</th>
<th class="text-center" style="width: 20%">Produk
</th>
<th class="text-center" style="width: 15%">kadaluarsa</th>
<th class="text-center" style="width: 15%">Harga</th>
<th class="text-center" style="width: 15%">Kuantiti</th>
<th class="text-center" style="width: 15%">Harga Satuan</th>
<th class="text-center" style="width: 15%">Harga Jual</th>
<th class="text-center" style="width: 15%">Aksi</th>
</tr>
</thead>
@foreach ($produk as $item)
<tbody>
<td class="text-center" style="width: 5%">
{{ $loop->iteration }}</td>
<td class="text-center" style="width: 20%">
{{ $item->produk->nama }}</td>
<td class="text-center" style="width: 15%">
{{ $item->kadaluarsa }}</td
<details>
<summary>英文:</summary>
hi i want to ask you something, i am having problem in my laravel project where i always find message "message": "Too few arguments to function App\\\\Http\\\\Controllers\\\\BursaPembelianController::edit_bursa_pembelian()....
please give me a solution to the problem I'm facing regarding the error message, below I provide the source code view that I made.
view:
@extends('layouts.main')
@section('container')
<body class="InvPinjam()">
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box d-sm-flex align-items-center justify-content-between">
<h4 class="mb-sm-0 font-size-18">{{ $label }}</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item">{{ ucwords($menu) }}</li>
<li class="breadcrumb-item">{{ ucwords($submenu) }}</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Kode Pembelian <code>*</code></label>
<input type="disable" class="form-control" id="kode_transaksi"
name="kode_transaksi" value="{{ $pembelian->kode_transaksi }}" disabled>
<input type="hidden" name="purchase_id" id="purchase_id"
value="{{ $pembelian->id }}">
<input type="hidden" name="url" id="url"
value="{{ Crypt::encryptString($pembelian->kode_transaksi) }}">
</div>
</div>
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Tanggal <code>*</code></label>
<input type="disable" class="form-control" name="tgl_kedatangan"
id="tgl_kedatangan" value="{{ $pembelian->tgl_kedatangan }}" readonly>
<input type="disable" class="form-control" name="id_peminjam" id="id_peminjam"
value="" hidden>
{!! $errors->first('nama_peminjam', '<div class="invalid-validasi">:message</div>') !!}
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Supplier </label>
<div class="input-group">
<input type="text" class="form-control" name="supplier" id="supplier"
value="{{ $pembelian->id_supplier }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
{!! $errors->first('tgl_permintaan', '<div class="invalid-validasi">:message</div>') !!}
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Surat Jalan </label>
<div class="input-group">
<input type="text" class="form-control" name="suratjalan" id="suratjalan"
value="{{ $pembelian->nomor_do }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Status Pembayaran </label>
<div class="input-group">
<input type="text" class="form-control" name="pembayaran" id="pembayaran"
value="{{ $pembelian->status_pembayaran }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
</div>
</div>
<div class="col-md-2 wajib">
<div class="mb-2">
<label>Potongan </label>
<div class="input-group">
<input type="text" class="form-control" name="potongan" id="potongan"
value="{{ $pembelian->potongan }}">
<span class="input-group-text"><i class="mdi mdi-calendar"></i></span>
</div>
</div>
</div>
</div>
{{-- keterengan --}}
<div class="row">
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Ongkir <code>*</code></label>
<input type="disable" class="form-control" id="kode_transaksi"
name="kode_transaksi" value="{{ $pembelian->ongkir ?? 0 }}">
</div>
</div>
<div class="col-md-2 peminjam">
<div class="mb-2">
<label>Keterangan <code>*</code></label>
<textarea id="keterangan" class="form-control" name="keterangan" style="height: 50px;" placeholder="Keterangan"></textarea>
</div>
</div>
</div>
</div>
{{-- //keterangan --}}
<div class="row">
<div class="col-md-12 table-responsive">
<table class="table table-responsive table-bordered table-striped" id="tableList">
<thead>
<tr>
<th class="text-center" style="width: 5%">No</th>
<th class="text-center" style="width: 20%">Produk
</th>
<th class="text-center" style="width: 15%">kadaluarsa</th>
<th class="text-center" style="width: 15%">Harga</th>
<th class="text-center" style="width: 15%">Kuantiti</th>
<th class="text-center" style="width: 15%">Harga Satuan</th>
<th class="text-center" style="width: 15%">Harga Jual</th>
<th class="text-center" style="width: 15%">Aksi</th>
</tr>
</thead>
@foreach ($produk as $item)
<tbody>
<td class="text-center" style="width: 5%">
{{ $loop->iteration }}</td>
<td class="text-center" style="width: 20%">
{{ $item->produk->nama }}</td>
<td class="text-center" style="width: 15%">
{{ $item->kadaluarsa }}</td>
<td class="text-center" style="width: 15%">
{{ $item->harga_total_produk }}</td>
<td class="text-center" style="width: 15%">
{{ $item->total_kuantiti }}</td>
<td class="text-center" style="width: 15%">
{{ $item->nilai_per_pcs }}</td>
<td class="text-center" style="width: 15%">
{{ $item->nilai_jual }}</td>
<td class="text-center">
<?php $id = Crypt::encryptString($item->id); ?>
<form class="delete-form"
action="{{ route('inv_pinjaman.destroy_invid', $id) }}"
method="POST">
@csrf
@method('DELETE')
<div class="d-flex gap-3">
<a href class="text-danger delete_confirm"><i
class="mdi mdi-delete font-size-18"></i></a>
</div>
</form>
</td>
</tbody>
@endforeach
</table>
</div>
</div>
<div class="row mt-4">
<div class="col-sm-12">
<button class="btn btn-primary" type="button" id="tambahBaris">Tambah
Baris</button>
</div>
</div>
<div class="row mt-4">
<div class="col-sm-12">
<a href="{{ route('bursa_pembelian.index') }}"
class="btn btn-secondary waves-effect">Kembali</a>
<button class="btn btn-success" type="button" id="simpanDataBtn">Simpan</button>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
</div>
</div>
</body>
<script src="{{ asset('assets/libs/jquery/jquery.min.js') }}"></script>
<script src="{{ asset('assets/alert.js') }}"></script>
<script>
//form tambah baris
document.getElementById("tambahBaris").addEventListener("click", function() {
var table = document.getElementById("tableList");
var row = table.insertRow();
var rowCount = table.rows.length;
var cell1 = row.insertCell(0);
cell1.innerHTML = rowCount;
var cell2 = row.insertCell(1);
var pilihProduk = document.createElement("select");
pilihProduk.className = "form-control select select2 produk";
pilihProduk.name = "produk";
pilihProduk.id = "produk";
pilihProduk.required = true;
var defaultOption = document.createElement("option");
defaultOption.value = "";
defaultOption.text = "--PILIH PRODUK--";
defaultOption.required = true;
pilihProduk.appendChild(defaultOption);
@foreach ($barang as $barangs)
var option = document.createElement("option");
option.value = "{{ $barangs->id }}";
option.dataset.id = "{{ $barangs->nama }}";
option.text = "{{ $barangs->nama }}";
pilihProduk.appendChild(option);
@endforeach
cell2.appendChild(pilihProduk);
$(pilihProduk).select2({
tags: true,
allowClear: true
});
//tangal kadaluarsa
var cell3 = row.insertCell(2);
var kadaluarsa = document.createElement("input");
kadaluarsa.type = "text";
kadaluarsa.className = "form-control";
kadaluarsa.name = "kadaluarsa";
kadaluarsa.id = "kadaluarsa";
kadaluarsa.placeholder = "Kadaluarsa";
kadaluarsa.required = true;
cell3.appendChild(kadaluarsa);
// Inisialisasi Datepicker
$(kadaluarsa).datepicker({
dateFormat: 'dd-mm-yy',
});
//Harga
var cell4 = row.insertCell(3);
cell4.innerHTML =
'<input type="number" class="form-control" name="harga" id="harga" placeholder="Total Harga" required>';
//kuantitas
var cell5 = row.insertCell(4);
cell5.innerHTML =
'<input type="number" class="form-control" min="1" name="kuantitas" id="kuantitas" placeholder="Jumlah" oninput="updateHargaSatuan(this)" required>';
//harga satuan
var cell6 = row.insertCell(5);
cell6.innerHTML =
'<input type="number" class="form-control" name="harsat" id="harsat" placeholder="harsat" readonly>';
//harga jual
var cell7 = row.insertCell(6);
cell7.innerHTML =
'<input type="number" class="form-control" name="harjual[]" id="harjual" placeholder="Harga Jual" required>';
//button hapus
var cell8 = row.insertCell(7);
cell8.innerHTML =
'<button class="btn btn-danger" type="button" onclick="hapusBaris(this)">Hapus</button>';
});
function hapusBaris(button) {
var row = button.parentNode.parentNode;
row.parentNode.removeChild(row);
}
//fungsi untuk mengisi harga satuan
function updateHargaSatuan(input) {
var row = input.parentNode.parentNode;
var hargaInput = row.querySelector('[name="harga"]');
var hargaSatuanInput = row.querySelector('[name="harsat"]');
var harga = parseFloat(hargaInput.value);
var kuantitas = parseFloat(input.value);
if (!isNaN(harga) && !isNaN(kuantitas) && kuantitas !== 0) {
var hargaSatuan = harga / kuantitas;
hargaSatuanInput.value = hargaSatuan.toFixed(2);
}
}
$('#simpanDataBtn').click(function() {
var dataedit = [];
$('#tableList tbody tr').each(function() {
var purchase_id = document.getElementById('purchase_id').value;
var kode_transaksi = document.getElementById('kode_transaksi').value;
var supplier = document.getElementById('supplier').value;
var suratjalan = document.getElementById('suratjalan').value;
var pembayaran = document.getElementById('pembayaran').value;
var potongan = document.getElementById('potongan').value;
var keterangan = document.getElementById('keterangan').value;
var produk = $(this).find('[name="produk"]').val();
var kadaluarsa = $(this).find('[name="kadaluarsa"]').val();
var harga = $(this).find('[name="harga"]').val();
var kuantitas = $(this).find('[name="kuantitas"]').val();
var hargaSatuan = $(this).find('[name="harsat"]').val();
var hargaJual = $(this).find('[name="harjual"]').val();
var rowData = {
purchase_id: purchase_id,
kode_transaksi: kode_transaksi,
supplier: supplier,
suratjalan: suratjalan,
pembayaran: pembayaran,
potongan: potongan,
keterangan: keterangan,
produk: produk,
kadaluarsa: kadaluarsa,
harga: harga,
kuantitas: kuantitas,
hargaSatuan: hargaSatuan,
hargaJual: hargaJual
};
dataedit.push(rowData);
});
$.ajax({
type: 'POST',
url: '{{ route('bursa_pembelian.edit_jumlah_pembelian') }}',
data: {
"_token": "{{ csrf_token() }}",
data: JSON.stringify({
data: dataedit
})
},
success: (response) => {
console.log(response)
if (response.code === 200) {
Swal.fire(
'Success',
`${response.message}`,
'success'
).then(() => {
var APP_URL = {!! json_encode(url('/')) !!}
console.log(APP_URL)
url = document.getElementById("url").value;
window.location = APP_URL + '/bursa/bursa_pembelian/' +
url +
'/edit'
})
} else {
Swal.fire(
'Gagal',
`${response.message}`,
'error',
)
}
},
error: err => console.log(err)
});
});
</script>
@endsection
web/routing:
Route::post('/edit_bursa_pembelian/{id}', [BursaPembelianController::class, 'edit_bursa_pembelian'])->name('bursa_pembelian.edit_jumlah_pembelian');
controller:
public function edit_bursa_pembelian(Request $request, $id)
{
$updatepembelian = new BursaDetilPembelian();
$updatepembelian->id_pembelian = $request->data['purchase_id'];
$updatepembelian->id_produk = $request->data['produk'];
$updatepembelian->harga_total_produk = $request->data['harga'];
$updatepembelian->total_kuantiti = $request->data['kuantitas'];
$updatepembelian->nilai_per_pcs = $request->data['hargaSatuan'];
$updatepembelian->nilai_jual = $request->data['hargaJual'];
$updatepembelian->user_updated = Auth::user()->id;
$updatepembelian->save();
}
Detail Error
"message": "Too few arguments to function App\\Http\\Controllers\\BursaPembelianController::edit_bursa_pembelian(), 1 passed in D:\\Leo\\dw\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php on line 54 and exactly 2 expected",
"exception": "ArgumentCountError",
"file": "D:\\Leo\\dw\\app\\Http\\Controllers\\BursaPembelianController.php",
"line": 311,
</details>
# 答案1
**得分**: 2
错误的原因是这个表达式:
```javascript
$.ajax({
type: 'POST',
url: '{{ route('bursa_pembelian.edit_jumlah_pembelian') }}',
当你使用带有一些参数的route
函数时,你必须传递它们。
例如(来源自laravel文档):
Route::get('/user/{id}/profile', function (string $id) {
// ...
})->name('profile');
$url = route('profile', ['id' => 1]);
因此,对于你的特定用例,你需要指定编辑资源的id($id
是占位符):
{{ route('bursa_pembelian.edit_jumlah_pembelian', ['id' => $id]) }}
英文:
The reason for error is this expression:
$.ajax({
type: 'POST',
url: '{{ route('bursa_pembelian.edit_jumlah_pembelian') }}',
When you are using route
function with route that has some parameters, you have to pass them.
For example (source from the laravel docs):
Route::get('/user/{id}/profile', function (string $id) {
// ...
})->name('profile');
$url = route('profile', ['id' => 1]);
So for your particular use case, you'd have to specify id of edited resource ($id
is placeholder):
{{ route('bursa_pembelian.edit_jumlah_pembelian', ['id' => $id]) }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论