storing the comments
This commit is contained in:
parent
ba57f19319
commit
e411e6297a
@ -2,15 +2,28 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Models\User;
|
||||
use App\Models\Comment;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
public function store()
|
||||
public function store(User $user, Post $post, Request $request)
|
||||
{
|
||||
// validate
|
||||
$request->validate([
|
||||
"comment" => "required|max:255"
|
||||
]);
|
||||
|
||||
// store
|
||||
dd("commenting...");
|
||||
Comment::create([
|
||||
"user_id" => auth()->user()->id,
|
||||
"post_id" => $post->id,
|
||||
"comment" => $request->comment
|
||||
]);
|
||||
|
||||
return back()->with('message', 'Comment added successfully');
|
||||
}
|
||||
}
|
||||
|
@ -8,4 +8,10 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
"user_id",
|
||||
"post_id",
|
||||
"comment"
|
||||
];
|
||||
}
|
||||
|
@ -29,6 +29,12 @@
|
||||
@auth
|
||||
<p class="text-xl font-bold text-center mb-4">Add a new Comment</p>
|
||||
|
||||
@if (session('message'))
|
||||
<p class="bg-green-500 text-white my-2 rounded-lg text-sm p-2 text-center">
|
||||
{{ session('message') }}
|
||||
</p>
|
||||
@endif
|
||||
|
||||
<form action="{{ route('comment.store', ['post' => $post, 'user' => $user]) }}" method="POST">
|
||||
@csrf
|
||||
<div class="mb-5">
|
||||
|
Loading…
x
Reference in New Issue
Block a user