skip to Main Content

I want a request a data from operation i made in controller, when i try my code the output total is null.

I try this code

$total += $request->jumlah_pinjaman;
$data = [
        'tanggal' => $request->tanggal,
        'no_bukti' => $request->no_bukti,
        'jumlah_pinjaman' => $request->jumlah_pinjaman,
        'uraian' => $request->uraian,
        'user_id' => $request->user_id,
        'total' => $request->$total
        ];
dd($data);

And the output is

array:6 [
  "tanggal" => "2023-11-29"
  "no_bukti" => "KSB231129290"
  "jumlah_pinjaman" => "100000"
  "uraian" => "garapan"
  "user_id" => "2"
  "total" => null
]

I want a total is not null

2

Answers


  1. 'total' => $request->$total
    

    should be

    'total' => $total
    
    Login or Signup to reply.
  2. $total += $request->jumlah_pinjaman;
    
    $data = [
        'tanggal' => $request->tanggal,
        'no_bukti' => $request->no_bukti,
        'jumlah_pinjaman' => $request->jumlah_pinjaman,
        'uraian' => $request->uraian,
        'user_id' => $request->user_id,
    
    **//This will use the variable $total directly rather than trying
    //to access it via the request object, as it seems you've already
    //calculated the total with $total += $request->jumlah_pinjaman.**
    
        'total' => $total 
    
    ];
    
    dd($data);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search