Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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
Laravel 拉韦尔马特维斯特酒店_Laravel - Fatal编程技术网

Laravel 拉韦尔马特维斯特酒店

Laravel 拉韦尔马特维斯特酒店,laravel,Laravel,我需要你的帮助。我不知道如何导入excel文件。我的意思是我不知道把这个users.xlsx放在哪里,以及如何获取它的目录 public function import() { Excel::import(new UsersImport, 'users.xlsx'); return redirect('/')->with('success', 'All good!'); } 这在Matt网站上很简单,您需

我需要你的帮助。我不知道如何导入excel文件。我的意思是我不知道把这个users.xlsx放在哪里,以及如何获取它的目录

 public function import()
        {
            Excel::import(new UsersImport, 'users.xlsx');

            return redirect('/')->with('success', 'All good!');
        }

这在Matt网站上很简单,您需要一个如下所示的控制器:

  public function importExcel(Request $request)
{
    if ($request->hasFile('import_file')) {
        Excel::load($request->file('import_file')->getRealPath(), function ($reader) {
            foreach ($reader->toArray() as $key => $row) {
// note that these fields are completely different for you as your database fields and excel fields so replace them with your own database fields
                $data['title'] = $row['title'];
                $data['description'] = $row['description'];
                $data['fax'] = $row['fax'];
                $data['adrress1'] = $row['adrress1'];
                $data['telephone1'] = $row['telephone1'];
                $data['client_type'] = $row['client_type'];


                if (!empty($data)) {
                    DB::table('clients')->insert($data);
                }
            }
        });
    }

    Session::put('success on import');

    return back();
}
Route::post('admin/client/importExcel', 'ClientController@importExcel');
还有这样一种观点:

                <form
                  action="{{ URL::to('admin/client/importExcel') }}" class="form-horizontal" method="post"
                  enctype="multipart/form-data">
                {{ csrf_field() }}
                <div class="form-group">
                    <label class="control-label col-lg-2">excel import</label>
                    <div class="col-lg-10">
                        <div class="uploader"><input type="file"  name="import_file" class="file-styled"><span class="action btn btn-default legitRipple" style="user-select: none;">choose file</span></div>
                    </div>
                </div>
                <button class="btn btn-primary">submit</button>
            </form>

你必须上传一个xls文件,然后导入到哪里上传文件,我的意思是在哪个文件夹?我的意思是通过文件上传的形式,如果文件是动态的。如果您的xls文件不是动态的,则将该文件添加到公共目录中,并使用public_path()帮助函数访问它。我正试图将其放入公共目录:Excel::import(new UsersImport,request()->file(public_path('users.xlsx'));但是它说存储/日志/拉腊维尔-2019-05-03日志不能打开流:权限DeNeDIT关于文件权限问题的检查,它对我说“未定义索引:名字”。=$row['name'];