app/Http/Controllers/BarangController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $this->validate($request,[
            "nama" => "required",
            "harga_awal" => "required",
            "tanggal" => "required",
            "deskripsi_barang" => "required",
            "nama" => "required",
        ]);
        $barang  = new Barang;
        $fileName = time()."_".Str::random(32).".".$request->photo->getClientOriginalExtension();
        $request->photo->move('images',$fileName);
        $barang->photo = $fileName;
        $barang->nama = $request->nama;
        $barang->harga_awal = $request->harga_awal;
        $barang->tanggal = $request->tanggal;
        $barang->deskripsi_barang = $request->deskripsi_barang;
        $barang->id_petugas = \Auth::user()->id;
        if($barang->save()){
            return redirect()->route('barang.show',[
                'id' => $barang->id
            ])->with('success','Data berhasil ditambah');
        }
        return redirect()->route('barang.show',[
            'id' => $barang->id
        ])->with('error','Data gagal ditambah');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ " nama " => " required " , " harga_awal " => " required " , " tanggal " => " required " , " deskripsi_barang " => " required " , " nama " => " required " , ] ) ; $ barang = new Barang ; $ fileName = time ( ) . " _ " . Str :: random ( 32 ) . " . " . $ request -> photo -> getClientOriginalExtension ( ) ; $ request -> photo -> move ( 'images' , $ fileName ) ; $ barang -> photo = $ fileName ; $ barang -> nama = $ request -> nama ; $ barang -> harga_awal = $ request -> harga_awal ; $ barang -> tanggal = $ request -> tanggal ; $ barang -> deskripsi_barang = $ request -> deskripsi_barang ; $ barang -> id_petugas = \ Auth :: user ( ) -> id ; if ( $ barang -> save ( ) ) { return redirect ( ) -> route ( 'barang.show' , [ 'id' => $ barang -> id ] ) -> with ( 'success' , 'Data berhasil ditambah' ) ; } return redirect ( ) -> route ( 'barang.show' , [ 'id' => $ barang -> id ] ) -> with ( 'error' , 'Data gagal ditambah' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//