Reputation: 75
I am trying to copy a file to my server Public Folder.
I am getting the following error :
BadMethodCallException in Macroable.php line 74: Method store does not exist.
This is the html to upload the file :
<form action="/leads/csvFiles" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<input type="file" name="csvfile" />
<input type="submit"/>
</form>
And here is the Route:
Route::post('leads/csvFiles', function(){
request()->file('csvfile')->store('Public');
return back();
});
Upvotes: 0
Views: 4420
Reputation: 12277
store()
method has been implemented from Laravel 5.3, you need to use something like:
Route::post('leads/csvFiles', function(){
$request->file('csvfile')->move('Public');
return back();
});
Its advised to check first if file is valid:
if ($request->file('csvfile')->isValid()) {
//next code here
}
Then you you can actually save the file with whatever name you want.
$request->file('csvfile')->move('Public', 'myfilename.csv');
Upvotes: 3