como corrigir erro de'未定义变量:名称'

时间:2019-04-13 00:21:11

标签: laravel

执行死刑的法律执行者

public function store(Request $request)
    {
        if ($request->hasfile('filename')) {
           `enter code here` $file = $request->file('filename');
            $name=time().$file->getClientOriginalName();
            $file->move(public_path().'/images/', $name);
        }
        $passport= new \App\Passport;
        $passport->name=$request->get('name');
        $passport->email=$request->get('email');
        $passport->number=$request->get('number');
        $date=date_create($request->get('date'));
        $format = date_format($date,"Y-m-d");
        $passport->date = strtotime($format);
        $passport->office=$request->get('office');
        $passport->filename=$name;
        $passport->save();

        return redirect('passports')->with('successo','informação adicionada');
}

1 个答案:

答案 0 :(得分:0)

尝试

public function store(Request $request)
    {
        if ($request->hasfile('filename')) {
           `enter code here` $file = $request->file('filename');
            $name=time().$file->getClientOriginalName();
            $file->move(public_path().'/images/', $name);
        }else{
            dd('no file input');//changed here
        }
        $passport= new \App\Passport;
        $passport->name=$request->get('name');
        $passport->email=$request->get('email');
        $passport->number=$request->get('number');
        $date=date_create($request->get('date'));
        $format = date_format($date,"Y-m-d");
        $passport->date = strtotime($format);
        $passport->office=$request->get('office');
        $passport->filename=$name;
        $passport->save();

        return redirect('passports')->with('successo','informação adicionada');
}