Skip to content

Commit

Permalink
Added ability to edit your post
Browse files Browse the repository at this point in the history
  • Loading branch information
WillTheDeveloper committed Mar 11, 2022
1 parent a9a7014 commit 222fbb5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
17 changes: 17 additions & 0 deletions app/Http/Controllers/Community.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,21 @@ public function leaveSubject($id) //POST REQUEST

return redirect(route('community'));
}

public function updatePost($id, Request $request)
{
$post = Post::query()->where('posts.id', $id);

$title = $request->input('title');
$body = $request->input('body');

$post->update(
[
'title' => $title,
'body' => $body
]
);

return redirect(route('community'));
}
}
29 changes: 25 additions & 4 deletions resources/views/community.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class="bg-transparent absolute inset-x-0 bottom-0 h-0.5"></span>
<ul role="list" class="space-y-4">
@forelse($posts as $post)
<li class="bg-white px-4 py-6 shadow sm:p-6 sm:rounded-lg"
x-data="{dropdown: false}">
x-data="{dropdown: false, edit: false, content: true}">
<article aria-labelledby="question-title-81614">
<div>
<div class="flex space-x-3">
Expand Down Expand Up @@ -318,7 +318,7 @@ class="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-white
<div class="py-1" role="none">
<!-- Active: "bg-gray-100 text-gray-900", Not Active: "text-gray-700" -->
@if ($post->user_id == auth()->id())
<a href="#"
<a href="#" x-on:click="edit = true; content = false"
class="text-gray-700 flex px-4 py-2 text-sm"
role="menuitem" tabindex="-1"
id="options-menu-0-item-0">
Expand Down Expand Up @@ -374,14 +374,35 @@ class="text-gray-700 flex px-4 py-2 text-sm"
</div>
</div>
</div>
<h2 id="question-title-81614"
<h2 id="question-title-81614" x-show="content"
class="mt-4 text-base font-medium text-gray-900">
{{$post->title}}
</h2>
</div>
<div class="mt-2 text-sm text-gray-700 space-y-4">
<p>{{$post->body}}</p>
<p x-show="content">{{$post->body}}</p>
</div>

<div x-show="edit" x-cloak>
<form method="post" action="{{ route('community.post.update', $post->id) }}">
@csrf
<div>
<label for="title" class="block text-sm font-medium text-gray-700">Title</label>
<div class="mt-1">
<input type="text" name="title" id="title" value="{{$post->title}}" class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md" placeholder="you@example.com">
</div>
</div>
<div>
<label for="body" class="block text-sm font-medium text-gray-700">Add your comment</label>
<div class="mt-1">
<textarea rows="4" name="body" id="body" class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md">{{$post->body}}</textarea>
</div>
</div>

<button type="submit" class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Update</button>
</form>
</div>

<div class="mt-6 flex justify-between space-x-8">
<div class="flex space-x-6">
<span class="inline-flex items-center text-sm">
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
Route::post('/users/{id}/update', [User::class, 'updateUser'])
->middleware(['auth', 'admin'])
->name('user.update');
Route::post('/community/post/{id}/update', [Community::class, 'updatePost'])
->middleware('auth')
->name('community.post.update');

//STRIPE
Route::get('/billing-portal', function (Request $request) {
Expand Down

0 comments on commit 222fbb5

Please sign in to comment.