Reputation: 1345
I use Laravel 5.4 and want to upload image. But in controllrt $request->hasFile('pic') returns false. This is my blade.php :
.
.
.
<form action="{{ route('my-url') }}" method="post">
<input type="file" name="pic">
</form>
.
.
.
And this is my controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class myclass extends Controller {
public function myfunc(Request $request) {
if($request->hasFile('pic')){
// never get this
}
}
}
Should i add another field to form or input in blade.php or controller?
Upvotes: 0
Views: 1468
Reputation: 21681
You should try this:
The form data being encoded as “multipart/form-data”
, which is required when files will be included as form data.
<form action="{{ route('my-url') }}" method="post" enctype="multipart/form-data">
<input type="file" name="pic">
</form>
Upvotes: 2
Reputation: 4040
just addd in your form
<form action="{{ route('my-url') }}" method="post" enctype="multipart/form-data">
<input type="file" name="pic">
</form>
//enctype="multipart/form-data" add this, this will your
Upvotes: 2