简体   繁体   中英

"Call to a member function move() on null"

When I detect using dd($ request-> toArray) there is a file but when moving files with the move function an error occurs because there is no input please give an explanation about that- 1 1

`public function index_tambah(Request $request){

   //dd($request->toArray());

    $validator = Validator::make($request->all(),
            [
                'namaMtr'       =>'required',
                'jenisMtr'      =>'required',
                'hargaMtr'      =>'required',
                'platMtr'       =>'required',
                'imgmtr'        => 'required',
                'keteranganMtr' => 'required',      

            ],
            [
                'namaMtr.required'      =>'Nama Harus Disikan',
                'jenisMtr.required'     =>'Jenis Harus Diisikan',
                'hargaMtr.required'     =>'Harga Harus diisikan',
                'platMtr.required'      =>'Plat Harus Diisikan',
                'imgmtr.required'       =>'Image Harus diisikan',
                'keteranganMtr.required'=>'Keterangan Harus diisikan',

            ]       
        );

            if($validator->fails()){
                return redirect()->back()
                    ->withErrors($validator)
                    ->withInput();
            }

                    $file = $request->file('imgmtr');

                    $nama_image = $file->getClientOriginalName();

                        dd($nama_image);

                    $tujuan_upload = 'upload';
                    $file->move($tujuan_upload,$file->getClientOriginalName());


            $new_tawaran = new Motor();
            $new_tawaran->namaMtr       =       $request->input('namaMtr');
            $new_tawaran->jenisMtr      =       $request->input('jenisMtr');
            $new_tawaran->platMtr      =        $request->input('platMtr');
            $new_tawaran->hargaMtr      =       $request->input('hargaMtr');
            $new_tawaran->keteranganMtr =       $request->input('hargaMtr');
            $new_tawaran->imgmtr        =       $file->getClientOriginalName();


            $new_tawaran->save();

        return redirect()->route('show_data');

}`

As far as I can tell, you're using $file = $request->file('imgmtr'); and there could be two problems:

If you're using default Laravel Request class, check your namespace on top of your controller, it should be like this: Illuminate\\Http\\Request .

If not that, you probably forgot to add enctype="multipart/form-data" to your form opening:

<form method="POST" action="#" enctype="multipart/form-data"> ... </form>

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