app/Http/Controllers/Admin/BeritaController.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)
    {
        $request->validate([
            'txtjudul_berita' => 'required',
            'txtfoto_berita' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:10000',
            'optionid_kategori_berita' => 'required',
            'txtisi_berita' => 'required',
        ]);
        $file = $request->file('txtfoto_berita');
        $nama_file = time() . "_" . $file->getClientOriginalName();
        $data_berita = new berita([
            'judul_berita' => $request->get('txtjudul_berita'),
            'foto_berita' => $nama_file,
            'id_kategori_berita' => $request->get('optionid_kategori_berita'),
            'isi_berita' => $request->get('txtisi_berita'),
        ]);
        $tujuan_upload = 'front/assets/img/berita';
        $file->move($tujuan_upload, $nama_file);
        $data_berita->save();
        return redirect('administrator/berita')->with('sukses', 'Berita berhasil disimpan');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'txtjudul_berita' => 'required' , 'txtfoto_berita' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:10000' , 'optionid_kategori_berita' => 'required' , 'txtisi_berita' => 'required' , ] ) ; $ file = $ request -> file ( 'txtfoto_berita' ) ; $ nama_file = time ( ) . " _ " . $ file -> getClientOriginalName ( ) ; $ data_berita = new berita ( [ 'judul_berita' => $ request -> get ( 'txtjudul_berita' ) , 'foto_berita' => $ nama_file , 'id_kategori_berita' => $ request -> get ( 'optionid_kategori_berita' ) , 'isi_berita' => $ request -> get ( 'txtisi_berita' ) , ] ) ; $ tujuan_upload = 'front/assets/img/berita' ; $ file -> move ( $ tujuan_upload , $ nama_file ) ; $ data_berita -> save ( ) ; return redirect ( 'administrator/berita' ) -> with ( 'sukses' , 'Berita berhasil disimpan' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// nama file // isi dengan nama folder tempat kemana file diupload // upload file