28 lines
739 B
PHP
28 lines
739 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Comment;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CommentController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'content' => 'required|string|max:1000',
|
|
'commentable_id' => 'required|integer',
|
|
'commentable_type' => 'required|string',
|
|
]);
|
|
|
|
$comment = Comment::create([
|
|
'user_id' => auth()->id(),
|
|
'content' => $validated['content'],
|
|
'commentable_id' => $validated['commentable_id'],
|
|
'commentable_type' => $validated['commentable_type'],
|
|
]);
|
|
|
|
return back()->with('success', 'Commentaire ajouté.');
|
|
}
|
|
}
|