Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在laravel中的数据库中保存文件名_Php_Mysql_Laravel - Fatal编程技术网

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

Php 无法在laravel中的数据库中保存文件名,php,mysql,laravel,Php,Mysql,Laravel,这是我在UploadController中的addData方法 public function addData(Request $request) { $this->validate($request, [ 'name' => 'required|min:1', 'email' => 'required|min:2', ]); if(Input::hasFile('

这是我在UploadController中的addData方法

    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';

        }

    }
它可能会自动使用文件名或不使用文件名获取所有内容
$request->all()函数如果您有其他解决方案,是否需要为我或t编写每个字段名?

尝试这样做:

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

我如何用它的名字来显示图像?也许我不理解你的问题,但是如果你问的是如何在模板中显示图像,只需使用像这样的
{asset('img/'.$profile->file_name..jpg')}
这是一个很有说服力的集合。通常您在控制器中获取数据,如
$profile=profile::find($id)并将此数据传递给视图
返回视图('profile.show',compact(['profile'])在视图中,您使用此集合显示模型中的任何数据。它只显示名称,不显示实际图片
$request['file_name'] = $fileName;
Profile::create($request->all());