I am trying to upload an image.
Here is my html form:
<form class="form" action="{{ URL::to('/alunos/cadastrar') }}" method="post" enctype=”multipart/form-data”>
<label for="nome" >Nome</label>
<input type="text" name="nome" placeholder="nome"><br><br>
<label for="serie" >Série</label>
<input type="text" name="serie" placeholder="serie"><br><br>
<label for="escola" >Escola</label>
<input type="text" name=escola placeholder="escola"><br><br>
<label for="turno" >Turno</label>
<input type="text" name=turno placeholder="Turno"><br><br>
<label for="documento" >Documento</label>
<input type="text" name=documento placeholder="documento"><br><br>
<label for="residencia" >Reside em</label>
<input type="text" name=residencia placeholder="Reside em"><br><br>
<label for="rota" >Rota</label>
<input type="text" name=rota placeholder="rota"><br><br>
<label for="data_nasc" >Data de Nascimento</label>
<input type="text" name=data_nasc placeholder="Data de Nascimnento"><br><br>
<label for="mae" >Mãe</label>
<input type="text" name=mae placeholder="Mãe"><br><br>
<label for="pai" >Pai</label>
<input type="text" name=pai placeholder="Pai"><br><br>
<label for="photo" >Foto</label>
<input type="file" name="photo" id="photo">
{{ csrf_field() }}
<br>
<input type="submit" value="Registrar!">
</form>
And here is the controller method:
public function submit(Request $request)
{
if ($request->hasFile('photo')) {
echo "OK";
}else{
echo "error";
}
return redirect('/');
}
Every time it runs, get the error message. And dd(request()->all()) gives the following.
array:12 [▼
"nome" => null
"serie" => null
"escola" => null
"turno" => null
"documento" => null
"residencia" => null
"rota" => null
"data_nasc" => null
"mae" => null
"pai" => null
"photo" => "23722217_17536056.jpg"
"_token" => "TPYBg3d8f3CdiQQnMbimprb5HQPkxqG5MSLdAUEa"
]
The 'photo' field doesn't actually have the file, just the file name.
I am working in a MacBook Pro with MAMP. In the top of controller code, I have the following:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Quotation;
use Datatables;
use App\aluno;
use View;
use PDF;
use DB;
How could I make this upload work?