Implement news management features: add author field and comments functionality in NewsResource, enhance HomePageController to fetch latest news, and create dedicated views for news display and commenting. Update routes for comment submission and adjust homepage to showcase recent news articles.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\News;
|
||||
use App\Models\Comment;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NewsPageController extends Controller
|
||||
{
|
||||
@@ -17,4 +19,17 @@ class NewsPageController extends Controller
|
||||
{
|
||||
return view('web.pages.news.show', compact('news'));
|
||||
}
|
||||
|
||||
public function storeComment(Request $request, News $news)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'message' => 'required|string',
|
||||
'author_name' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$news->comments()->create($validated);
|
||||
|
||||
return back()->with('success', 'Comment added successfully!');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user