I want to display the total amount from start date and end date from tgl_trans, nasabah_id, jenis_id ??
$start = Carbon::parse($request->input('start'))->startOfDay();
$end = Carbon::parse($request->input('end'))->endOfDay();
$query = Transaksi::whereDate('tgl_trans', '>=', $start)->whereDate('tgl_trans', '<=', $end)->where('nasabah_id', $id)->get();
$kredit = $query->where('jenis_id', 1)->sum('nominal'); //result 0
Table transaksi
Schema::create('transaksis', function (Blueprint $table) {
$table->id();
$table->string('kode_trans');
$table->('nasabah_id');
$table->decimal('saldo_awal', $precision = 15, $scale = 2)->nullable();
$table->unsignedBigInteger('jenis_id');
$table->foreign('jenis_id')->references('id')->on('jenis')->onDelete('cascade')->onUpdate('cascade');
$table->decimal('nominal', $precision = 15, $scale = 2)->nullable();
$table->decimal('saldo', $precision = 15, $scale = 2)->nullable();
$table->integer('diff_day')->nullable();
$table->unsignedBigInteger('user_id');
$table->date('tgl_trans');
$table->timestamps(); });
value on $kredit not 0
2
Answers
Hard to debug the code, so I’ll leave a few suggestions:
Make sure that the
$id
exists, is set, and is not null/zero (i.e. is valid).check if the query is empty
First of all your migration file at line no-3 columns data type should be
Other all I tried myself was ok with & output , you may try by entering menual data as flowing
If its ok, then you have to check you requested input fields else you may check your database data.
Hope it will help.