Skip to content
Snippets Groups Projects
Commit 371c51a8 authored by LIENHARDT QUENTIN's avatar LIENHARDT QUENTIN :snake:
Browse files

Edit answer if user in a form + updated at

parent c3ae7e08
Branches stats
No related merge requests found
......@@ -64,7 +64,7 @@ class AnswerController extends Controller
*/
public function edit(Answer $answer)
{
return;
return view('answer.edit', ['answer' => $answer]);
}
/**
......@@ -76,7 +76,11 @@ class AnswerController extends Controller
*/
public function update(AnswerRequest $request, Answer $answer)
{
return;
$data = $request->validated();
$answer->fill($data);
$answer->save();
// Redirect to current subject
return redirect()->route('subject.show', $answer->subject_id);
}
/**
......
......@@ -1110,6 +1110,10 @@ select {
margin-top: 0.75rem;
margin-bottom: 0.75rem;
}
.my-1 {
margin-top: 0.25rem;
margin-bottom: 0.25rem;
}
.ml-3 {
margin-left: 0.75rem;
}
......@@ -1188,6 +1192,9 @@ select {
.inline-block {
display: inline-block;
}
.inline {
display: inline;
}
.flex {
display: flex;
}
......@@ -1528,6 +1535,10 @@ select {
--tw-bg-opacity: 1;
background-color: rgba(16, 185, 129, var(--tw-bg-opacity));
}
.bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgba(59, 130, 246, var(--tw-bg-opacity));
}
.bg-opacity-25 {
--tw-bg-opacity: 0.25;
}
......
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ 'Edit answer' }}
</h2>
</x-slot>
<p>published : {{ date('d-m-Y H:i', strtotime($answer->created_at)) }}</p>
<form action="{{ route('answer.update', $answer) }}" method="POST">
@csrf
@method('PUT')
<textarea name="content" placeholder="Content">{{ old('content', $answer->content) }}</textarea>
<br>
<button type="submit" class="p-1 bg-green-500 text-white">Edit !</button>
</form>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
</x-app-layout>
\ No newline at end of file
......@@ -13,8 +13,13 @@
@foreach ($subject->answers as $answer)
<div class="my-3 p-3 bg-gray-300">
<p>{{ date('d-m-Y H:i', strtotime($answer->created_at)) }} - {{ $answer->user }}</p>
<p>{{ date('d-m-Y H:i', strtotime($answer->updated_at)) }} - {{ $answer->user }}</p>
<p>{{ $answer->content }}</p>
@if (Auth::user() && Auth::user()->name == $answer->user)
<p class="my-1">
<a href="{{ route('answer.edit', $answer) }}" class="bg-blue-500 text-white p-1 inline-block">Edit</a>
</p>
@endif
</div>
@endforeach
......
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