douqie6454 2016-05-25 09:55
浏览 24
已采纳

无法在laravel中的数据库中保存文件名

this is my addData method in UploadController

    public function addData(Request $request)
    {
        $this->validate($request, [
            'name' => 'required|min:1',
            'email' => 'required|min:2',
        ]);

        if(Input::hasFile('file'))
        {
            $file = array('file' => Input::file('file'));
            $rules = array('file' => 'required|mimes:jpg,png,jpeg');
            $validator = Validator::make($file, $rules);

            if ($validator->fails()) {
                echo 'Not allowed!!';
            }
            else
            {
                if (Input::file('file')->isValid()) {
                    $destinationPath = 'uploads';
                    $name = Input::get('name');
                    $email = Input::get('email');
                    $extension = Input::file('file')->getClientOriginalExtension();
                    $fileName = Input::file('file')->getClientOriginalName();
                    $displayImage = Input::file('file')->move($destinationPath, $fileName);
                    $user = Profile::create([
                        'name' => $name,
                        'email' => $email,
                        'file_name' => $fileName,
                    ]);

$fileName]));

                    echo 'Upload Succesfully <br>';
           }

                else {
                    Session::flash('error', 'uploaded file is not valid');
                    return Redirect::to('upload');
                }
            }
        }
        else
        {
            echo 'Nothing to upload';

        }

    }

this is working fine but when i change to this it save name and email but not file name what is the problem with this i am failed to find out problem

Profile::create($request->all(['file_name' => $fileName]));

it is possible that it take everything automatically with filename or not with $request->all() function any other solution if you have for me or t is necessary to write every field name ?

  • 写回答

1条回答 默认 最新

  • douwen5584 2016-05-25 10:04
    关注

    Try to do it like this:

    $request['file_name'] = $fileName;
    Profile::create($request->all());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料