简体   繁体   中英

How to pass array from view controller in laravel

i make table in blade.php, and i want to pass array value to controller, here is my blade.php

@foreach ($alats as $data)
<tr>
        <td align="center" style="border-bottom: 3px solid {{$warna}}">{{$no}}</td>
        <td align="center" style="border-bottom: 3px solid {{$warna}}" name="no_inventaris[]">{{$data->no_inventaris}}</td>
        <td align="center"  style="border-bottom: 3px solid {{$warna}}" name="kode_alat[]">{{$data->kode_alat}}</td>
        <td align="center"  style="border-bottom: 3px solid {{$warna}}" name="tahun[]">{{$data->tahun}}</td>
        <td align="center"  style="border-bottom: 3px solid {{$warna}}" name="jenis_alat[]">{{$data->jenis_alat}}</td>
        <td align="center"  style="border-bottom: 3px solid {{$warna}}" name="merk_alat[]">{{$data->merk_alat}}</td>
        <td align="center"  style="border-bottom: 3px solid {{$warna}}" name="tipe_alat[]">{{$data->tipe_alat}}</td>
    </tr>

and i want to pass no_inventaris value to controller

public function kirimsemua(Request $request){
        $namas = $request->nama;
        $ids = $request->no_inventaris->get();

        $get_alat = Alat::whereIn('no_inventaris',$ids)->get();

        $permohonan[] = new Permohonan;
        foreach ($get_alat as $key) {
            $permohonan = new Permohonan;
            $permohonan->no_inventaris = $ids;
            $permohonan->tanggal_permohonan = date("Y-m-d");
            $permohonan->tindakan = "";
            $permohonan->nama_pengirim = $request->nama;
            $permohonan->kode_lokasi = $get_alat->kode_lokasi;
            $permohonan->id_workcenter = $get_alat->id_workcenter;
            $permohonan->alasan = $request->input_alasan;
            $permohonan->save();
        }

        DB::table('q_alat')->whereIn('no_inventaris', $ids)
        ->update(['status' => 'terkirim']);

        return redirect('request_kalibrasi_user/'.$namas)->with('sort',"1");
}

but it always gets error

Call to a member function get() on null

Use $request->get() method.

$namas = $request->get('namas');
$noInventarisIds = $request->get('no_inventaris');

// ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM