I'm trying to use Jasny's upload file ( link ) to upload photos and save the name photo in the DB with Laravel 5.1 but it is not working.
Apparently the laravel is capturing the photo when I give the command dd(Request::capture());
it brings the data as shown below.
Butitisshowingthefollowingerror:
WhatwouldbeinthisLine
$extension=$file->getClientOriginalExtension();//gettingimageextension
Followthecode
View
<formmethod="post" class="form-group" role="form" id="form" action=".../perfil/update" enctype="multipart/form-data">
<div class="form-group">
<label>Imagem de Perfil </label>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail">
<img src="assets/upload/avatar/avatar.png" alt="">
</div>
<div class="fileinput-preview fileinput-exists thumbnail"></div>
<div class="user-edit-image-buttons">
<span class="btn btn-azure btn-file">
<span class="fileinput-new"><i class="fa fa-picture"></i> Selecione uma imagem</span>
<span class="fileinput-exists"><i class="fa fa-picture"></i>Trocar</span>
<input type="file" id="file" name="foto"> </span>
<a href="#" class="btn fileinput-exists btn-red" data-dismiss="fileinput">
<i class="fa fa-times"></i> Cancelar</a>
</div>
</div>
</div>
Controller
public function update()
{
$id = $this->request->get('id');
$dadosForm = $this->request->except('_token');
//
//Recebe o Arquivo do Form
$file = $this->request->file('foto');
if($this->request->hasFile('foto') && $file->isValid()) {
$destinationPath = '/upload/profile/';
$extension = $file->getClientOriginalExtension(); // getting image extension
$fileName = rand(11111,99999).'.'.$extension; // renameing image
$file->move($destinationPath, $fileName); // uploading file to given path
}
if (isset($fileName)) $dadosForm = $this->associado->user_pic = $fileName;
$this->associado->where('id', $id)->update($dadosForm);
}