feat: add comments for controller and model and blade for dashboard for user
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\CommentPostRequest;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Tour;
|
||||
use App\Models\Flight;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
public function store(CommentPostRequest $request)
|
||||
{
|
||||
if ($request->commentable_type === 'tour') {
|
||||
$modelClass = Tour::class;
|
||||
} else {
|
||||
$modelClass = Flight::class;
|
||||
}
|
||||
$guestName = null;
|
||||
if (!auth()->check()) {
|
||||
$guestName = $request->guest_name;
|
||||
}
|
||||
Comment::create([
|
||||
'user_id' => auth()->id(),
|
||||
'guest_name' => $guestName,
|
||||
'commentable_id' => $request->commentable_id,
|
||||
'commentable_type' => $modelClass,
|
||||
'body' => $request->body,
|
||||
]);
|
||||
|
||||
return back()->with('success', 'نظر شما با موفقیت ثبت شد.');
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$comments = auth()->user()->comments()->with('commentable')->latest()->get();
|
||||
|
||||
return view('dashboard.comments', compact('comments'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user