Level 1
which framework use in laravel?
Hi everybody, I'm new using Laravel. I want to upload a image into public/images/avatar, so in my index.blade.view I have:
<div class="row" ng-controller="DisciplinesController" ng-init="getList()" ng-submit="create()">
<div class="col-xs-12">
<div class="white-box">
<div class="row">
<form id="newDiscipline" name="newDiscipline" ng-submit="create()" enctype="multipart/form-data" ng-init="file = {}">
<h4 class="text-success">Registrar disciplina</h4>
<div class="form-group col-md-12">
<div class="form-group col-md-6">
<label>Nombre:</label>
<input type="text" ng-model="discipline.name" ng-required="true" class="form-control" />
</div>
<div class="form-group col-md-6">
<label>Archivo</label>
<input type="file" name="file" fileread="discipline.file" class="form-control" ng-required="true"
accept=".png, .jpg, .jpeg"/>
</div>
</div>
<div class="col-md-12 text-right">
<button class="btn btn-success" ng-disabled="newDiscipline.$invalid">
<span class="fa fa-save"></span> Guardar
</button>
</div>
</form>
<h4 class="text-success">Disciplinas registradas</h4>
<table class="table">
<thead>
<tr>
<th>Nombre</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="discipline in disciplines">
<td>[[ discipline.name ]]</td>
<td>
<small>
<button class="btn btn-xs btn-danger" ng-click="remove(discipline.id)">
<span class="fa fa-trash"></span> Eliminar Disciplina
</button>
</small>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
And in my PHP Controller I have:
public function create(Request $request)
{
$name = $request->get('name');
$exists = Disciplines::where('name', $name)->first();
if(empty($exists))
{
$discipline = new Disciplines();
$discipline->name = $name;
$discipline->save();
$file = $request->file('file');
Storage::disk('local')->put("".$discipline->id."png", file_get_contents($request->file('file')->getRealPath()));
return response()->json($discipline)->setStatusCode(201);
}
}
But when I try to save the image appears that $file is null.
Can anyone help me? Thank you.
Please or to participate in this conversation.