save assets

mail@pastecode.io avatar
unknown
php
a month ago
13 kB
2
Indexable
Never
public function insert(Request $request)
    {
        Request()->validate(
            [
                'no_asset_eam' => 'unique:assets,no_asset_eam|max:8',
                'foto_rtu' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_name_plate' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_backup_suplai' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_tiang' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_panel' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_bangunan' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_susunan_kubikel' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell1' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell2' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell3' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell4' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell5' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell6' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell7' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell8' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_nameplate_cell9' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell1' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell2' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell3' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell4' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell5' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell6' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell7' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell8' => 'mimes:jpg,jpeg,bmp,png|max:15000',
                'foto_cell9' => 'mimes:jpg,jpeg,bmp,png|max:15000',
            ],
            [
                'no_asset_eam.unique' => 'Data Sudah Ada',
                'no_asset_eam.max' => 'Maximal 8 Karakter !!',
                'foto_rtu.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_rtu.max' => 'Maximal ukuran file 15 MB',
                'foto_name_plate.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_name_plate.max' => 'Maximal ukuran file 15 MB',
                'foto_backup_suplai.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_backup_suplai.max' => 'Maximal ukuran file 15 MB',
                'foto_tiang.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_tiang.max' => 'Maximal ukuran file 15 MB',
                'foto_panel.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_panel.max' => 'Maximal ukuran file 15 MB',
                'foto_bangunan.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_bangunan.max' => 'Maximal ukuran file 15 MB',
                'foto_susunan_kubikel.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_susunan_kubikel.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell1.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell1.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell2.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell2.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell3.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell3.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell4.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell4.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell5.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell5.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell6.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell6.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell7.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell7.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell8.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell8.max' => 'Maximal ukuran file 15 MB',
                'foto_nameplate_cell9.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_nameplate_cell9.max' => 'Maximal ukuran file 15 MB',
                'foto_cell1.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell1.max' => 'Maximal ukuran file 15 MB',
                'foto_cell2.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell2.max' => 'Maximal ukuran file 15 MB',
                'foto_cell3.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell3.max' => 'Maximal ukuran file 15 MB',
                'foto_cell4.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell4.max' => 'Maximal ukuran file 15 MB',
                'foto_cell5.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell5.max' => 'Maximal ukuran file 15 MB',
                'foto_cell6.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell6.max' => 'Maximal ukuran file 15 MB',
                'foto_cell7.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell7.max' => 'Maximal ukuran file 15 MB',
                'foto_cell8.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell8.max' => 'Maximal ukuran file 15 MB',
                'foto_cell9.mimes' => 'Extension File Harus .jpg, .jpeg, .bmp, atau, .png',
                'foto_cell9.max' => 'Maximal ukuran file 15 MB',
            ]
        );

        // Simpan setiap file ke penyimpanan (storage)
        $images = [
            'foto_rtu', 'foto_name_plate', 'foto_backup_suplai', 'foto_tiang', 'foto_panel',
            'foto_bangunan', 'foto_susunan_kubikel', 'foto_nameplate_cell1', 'foto_nameplate_cell2',
            'foto_nameplate_cell3', 'foto_nameplate_cell4', 'foto_nameplate_cell5', 'foto_nameplate_cell6',
            'foto_nameplate_cell7', 'foto_nameplate_cell8', 'foto_nameplate_cell9', 'foto_cell1', 'foto_cell2',
            'foto_cell3', 'foto_cell4', 'foto_cell5', 'foto_cell6', 'foto_cell7', 'foto_cell8', 'foto_cell9'
        ];

        // $defaultImage = 'default.jpg';

        // foreach ($images as $image) {
        //     $file = $request->file($image);

        //     if ($file) {
        //         // Simpan file ke penyimpanan (storage)
        //         $fileName = time() . '_' . $image . '_' . $file->getClientOriginalName();
        //         $path = $file->storeAs('public/' . $image, $fileName);
        //         $$image = $fileName;
        //     } else {
        //         $$image = $defaultImage;
        //     }
        // }

        foreach ($images as $image) {
            $file = $request->file($image);
            $fileName = $file ? time() . '_' . $image . '_' . $file->getClientOriginalName() : null;
            $path = $file ? $file->storeAs('public/' . $image, $fileName) : null;
            $$image = $fileName;
        }


        $data = [
            'no_asset_eam' => Request()->no_asset_eam,
            'location_eam' => Request()->location_eam,
            'parent_asset_eam' => Request()->parent_asset_eam,
            'meter_grub_eam' => Request()->meter_grub_eam,
            'gardu_induk' => Request()->gardu_induk,
            'trafo_daya' => Request()->trafo_daya,
            'penyulang' => Request()->penyulang,
            'nama_keypoint' => Request()->nama_keypoint,
            'type_keypoint' => Request()->type_keypoint,
            'koordinat' => Request()->koordinat,
            'id_up3' => Request()->id_up3,
            'id_ulp' => Request()->ulp,
            'remote_set' => Request()->remote_set,
            'foto_rtu' => $foto_rtu,
            'foto_name_plate' => $foto_name_plate,
            'tgl_oprasi' => Request()->tgl_oprasi,
            'tgl_integrasi' => Request()->tgl_integrasi,
            'status_scada' => Request()->status_scada,
            'sn_rtu' => Request()->sn_rtu,
            'tgl_pasang_batrei' => Request()->tgl_pasang_batrei,
            'foto_backup_suplai' => $foto_backup_suplai,
            'merk_backup_suplai' => Request()->merk_backup_suplai,
            'thn_backup_suplai' => Request()->thn_backup_suplai,
            'merk_rtu' => Request()->merk_rtu,
            'sectionalizer' => Request()->sectionalizer,
            'foto_tiang' => $foto_tiang,
            'vt_terpasang' => Request()->vt_terpasang,
            'sr_terpasang' => Request()->sr_terpasang,
            'foto_panel' => $foto_panel,
            'foto_bangunan' => $foto_bangunan,
            'foto_susunan_kubikel' => $foto_susunan_kubikel,
            'grounding' => Request()->grounding,
            'cell1' => Request()->cell1,
            'ratio_ct1' => Request()->ratio_ct1,
            'foto_nameplate_cell1' => $foto_nameplate_cell1,
            'foto_cell1' => $foto_cell1,
            'merk_relay1' => Request()->merk_relay1,
            'ar_pmt1' => Request()->ar_pmt1,
            'ratio_vt1' => Request()->ratio_vt1,
            'cell2' => Request()->cell2,
            'ratio_ct2' => Request()->ratio_ct2,
            'foto_nameplate_cell2' => $foto_nameplate_cell2,
            'foto_cell2' => $foto_cell2,
            'merk_relay2' => Request()->merk_relay2,
            'ar_pmt2' => Request()->ar_pmt2,
            'ratio_vt2' => Request()->ratio_vt2,
            'cell3' => Request()->cell3,
            'ratio_ct3' => Request()->ratio_ct3,
            'foto_nameplate_cell3' => $foto_nameplate_cell3,
            'foto_cell3' => $foto_cell3,
            'merk_relay3' => Request()->merk_relay3,
            'ar_pmt3' => Request()->ar_pmt3,
            'ratio_vt3' => Request()->ratio_vt3,
            'cell4' => Request()->cell4,
            'ratio_ct4' => Request()->ratio_ct4,
            'foto_nameplate_cell4' => $foto_nameplate_cell4,
            'foto_cell4' => $foto_cell4,
            'merk_relay4' => Request()->merk_relay4,
            'ar_pmt4' => Request()->ar_pmt4,
            'ratio_vt4' => Request()->ratio_vt4,
            'cell5' => Request()->cell5,
            'ratio_ct5' => Request()->ratio_ct5,
            'foto_nameplate_cell5' => $foto_nameplate_cell5,
            'foto_cell5' => $foto_cell5,
            'merk_relay5' => Request()->merk_relay5,
            'ar_pmt5' => Request()->ar_pmt5,
            'ratio_vt5' => Request()->ratio_vt5,
            'cell6' => Request()->cell6,
            'ratio_ct6' => Request()->ratio_ct6,
            'foto_nameplate_cell6' => $foto_nameplate_cell6,
            'foto_cell6' => $foto_cell6,
            'merk_relay6' => Request()->merk_relay6,
            'ar_pmt6' => Request()->ar_pmt6,
            'ratio_vt6' => Request()->ratio_vt6,
            'cell7' => Request()->cell7,
            'ratio_ct7' => Request()->ratio_ct7,
            'foto_nameplate_cell7' => $foto_nameplate_cell7,
            'foto_cell7' => $foto_cell7,
            'merk_relay7' => Request()->merk_relay7,
            'ar_pmt7' => Request()->ar_pmt7,
            'cell8' => Request()->cell8,
            'ratio_ct8' => Request()->ratio_ct8,
            'foto_nameplate_cell8' => $foto_nameplate_cell8,
            'foto_cell8' => $foto_cell8,
            'merk_relay8' => Request()->merk_relay8,
            'ar_pmt8' => Request()->ar_pmt8,
            'ratio_vt8' => Request()->ratio_vt8,
            'cell9' => Request()->cell9,
            'ratio_ct9' => Request()->ratio_ct9,
            'foto_nameplate_cell9' => $foto_nameplate_cell9,
            'foto_cell9' => $foto_cell9,
            'merk_relay9' => Request()->merk_relay9,
            'ar_pmt9' => Request()->ar_pmt9,
            'ratio_vt9' => Request()->ratio_vt9,
            'medkom' => Request()->medkom,
            'gtw_icon' => Request()->gtw_icon,
            'gtw_modem' => Request()->gtw_modem,
            'ip_rtu_modem' => Request()->ip_rtu_modem,
            'sn_modem' => Request()->sn_modem,
            'no_simcard' => Request()->no_simcard
        ];

        $insertAsset = AssetsModel::create($data);
        session()->flash('pesan', 'Data berhasil ditambahkan!');
        return redirect()->route('keypoint');
        // dd($data);
    }
Leave a Comment