简体   繁体   中英

Uploading excel file Laravel

I try to upload an excel file with a form in Laravel but I have the issue : Call to a member function store() on a non-object

Here is my code :

{!! Form::open(['route' => 'choixcol']) !!}
  <div class="col-md-4">
     {!! Form::file('data', '', ['id' =>  'file', 'class' =>  'form-control']) !!}
  </div>
  <div class="col-md-8">
     {!! Form::submit("Utiliser ce fichier", array('class' => 'btn btn-info')) !!}
  </div>

{!! Form::close() !!} 

And my function in my Controller:

public function upload(Request $request) {
    $path = $request->file('data')->store('data');
    return view('mesures.index');
}

How to solve it please?

EDIT :

In my $request I have :

Request {#37 ▼
  #json: null
  #sessionStore: null
  #userResolver: Closure {#231 ▶}
  #routeResolver: Closure {#248 ▶}
  +attributes: ParameterBag {#39 ▶}
  +request: ParameterBag {#38 ▼
  #parameters: array:2 [▼
   "_token" => "6IPVFkzu8o2jH244y0BwJEqKDqfWrt5pKwMS7Pls"
   "data" => "99081D_Pesee2016.xlsx"
  ]
}
+query: ParameterBag {#45 ▶}
+server: ServerBag {#42 ▶}
+files: FileBag {#41 ▶}
+cookies: ParameterBag {#40 ▶}
+headers: HeaderBag {#43 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/mesures/choix"
#requestUri: "/mesures/choix"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session: Store {#205 ▶}
#locale: null
#defaultLocale: "en"
}

I think I just get the name of the file but not the file directly...

The error is saying that file('data') is not an object in this case.

I would Log the $request array like Log::debug($request); and see what you have access to.

https://laravel.com/docs/5.3/requests#storing-uploaded-files

我找到了解决方案 ,它非常简单:我忘记为表单设置'files'=> true了!

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