adhik13th
1 month ago
208
5
Laravel

How to loop number and saved into table laravel

Posted 1 month ago by adhik13th

I have input and this input is will generate number sequentially like this

5.01
5.02
5.03
......
5.10
5.11

i get number 5 on first number is from my another data . u can see at my code .so how i can do this if this number start from '01' not '1' and if more than 10 this '0' in first number is deleted.

in my controller i saved in $data and looping this number from 01 So in my input controller is like that :

 public function store(Request $request)
{   

    $data = $request['kode_induk'] + // i dont know what to do here for loop this input , 

    $induk = IndukBelanja::create([
       'user_id' => Auth::user()->id,
       'kode_induk' => $request['kode_induk'],
       'kode_rekening' => $data,
       'uraian' => $request['uraian'],
       'anggaran' => $request['anggaran'],
    ]);

    if ($induk) {
        return ['redirect' => route('rekening_induk')];
    } else {
        return response()->json([
            'success' => false,
            'message' => ' Gagal update!',
        ], 500);
    }
}

how i can loop this number ? can someone help ?

Update its my database what i need

+----+------------+------------+------------+
| id |kode_induk  |kode_rekening|   uraian
+----+------------+------------+------------+
|  1 |   5        |   5.01     |    some data   
+----+------------+------------+------------+
|  2 |   5        |   5.02     |    some data   
+----+------------+------------+------------+
|  3 |   5        |   5.03     |    some data 
+----+------------+------------+------------+
|  4 |   5        |   5.04     |    some data   
+----+------------+------------+------------+

Please sign in or create an account to participate in this conversation.