Commit de3b0e3b authored by Lucas Henrique's avatar Lucas Henrique
Browse files

Corrige bug ao editar o plano de trabalho de um projeto sem discente

parent 5ac2f872
...@@ -853,6 +853,7 @@ class TrabalhoController extends Controller ...@@ -853,6 +853,7 @@ class TrabalhoController extends Controller
]); ]);
$trabalho = Trabalho::find($id); $trabalho = Trabalho::find($id);
$trabalho->ods()->sync($request->ods); $trabalho->ods()->sync($request->ods);
$proponente = Proponente::where('user_id', Auth::user()->id)->first();
DB::beginTransaction(); DB::beginTransaction();
if (!$trabalho) { if (!$trabalho) {
...@@ -1020,6 +1021,39 @@ class TrabalhoController extends Controller ...@@ -1020,6 +1021,39 @@ class TrabalhoController extends Controller
} }
} else {
$data['nomePlanoTrabalho'] = $request->nomePlanoTrabalho;
if (Arquivo::where('proponenteId', $proponente->id)->where('trabalhoId', $trabalho->id)->count()) {
$arquivo = Arquivo::where('proponenteId', $proponente->id)->where('trabalhoId', $trabalho->id)->first();
$path = 'trabalhos/' . $evento->id . '/' . $trabalho->id . '/';
$nome = $data['nomePlanoTrabalho'] . ".pdf";
$titulo = $data['nomePlanoTrabalho'];
if ($request->has('anexoPlanoTrabalho')) {
$file = $request->anexoPlanoTrabalho;
Storage::putFileAs($path, $file, $nome);
} else {
Storage::rename( $arquivo->nome, $path.$nome );
}
$arquivo->update([
'titulo' => $titulo,
'nome' => $path . $nome,
'data' => now(),
]);
} else {
$path = 'trabalhos/' . $evento->id . '/' . $trabalho->id . '/';
$nome = $data['nomePlanoTrabalho'] . ".pdf";
$file = $request->anexoPlanoTrabalho;
Storage::putFileAs($path, $file, $nome);
$arquivo = new Arquivo();
$arquivo->titulo = $data['nomePlanoTrabalho'];
$arquivo->nome = $path . $nome;
$arquivo->trabalhoId = $trabalho->id;
$arquivo->data = now();
$arquivo->proponenteId = $proponente->id;
$arquivo->versaoFinal = true;
$arquivo->save();
}
} }
DB::commit(); DB::commit();
......
...@@ -130,7 +130,7 @@ ...@@ -130,7 +130,7 @@
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
<br> <br>
<input type="file" class="input-group-text" value="{{old('anexoPlanoTrabalho') ?? "" }}" name="anexoPlanoTrabalho" accept=".pdf" placeholder="Anexo do Plano de Trabalho" /> <input type="file" class="input-group-text" value="{{old('anexoPlanoTrabalho') ?? '' }}" name="anexoPlanoTrabalho" accept=".pdf" placeholder="Anexo do Plano de Trabalho" />
@error('anexoPlanoTrabalho') @error('anexoPlanoTrabalho')
<span class="invalid-feedback" role="alert" style="overflow: visible; display:block"> <span class="invalid-feedback" role="alert" style="overflow: visible; display:block">
<strong>{{ $message }}</strong> <strong>{{ $message }}</strong>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment