git commit "add comments and fix tour comments display"

This commit is contained in:
2026-08-17 13:33:37 +03:30
parent 970786ae94
commit 902384625b
11 changed files with 729 additions and 166 deletions
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Http\Requests\CommentStoreRequest;
use App\Models\Comment;
use Illuminate\Http\Request;
@@ -18,4 +19,27 @@ class CommentController extends Controller
return view('account.users.comments.index',compact('comments'));
}
public function store(CommentStoreRequest $request)
{
$data = $request->validated();
$data['user_id'] = auth()->id();
$data['status'] = 0;
Comment::create([
'flight_id' => $request->flight_id,
'tour_id' => $request->tour_id,
'comment' => $request->comment,
'rating' => $request->rating,
'user_id' => auth()->id(),
'status' => 0,
]);
return back()->with(
'success',
'نظر شما با موفقیت ثبت شد و پس از بررسی نمایش داده می‌شود.'
);
}
}
+6 -1
View File
@@ -24,7 +24,12 @@ class FlightController extends Controller
{
$flight->increment('views');
return view('flights.show', compact('flight'));
$comments = $flight->comments()
->latest()
->get();
return view('flights.show', compact('flight','comments'));
}
}
+6 -1
View File
@@ -24,7 +24,12 @@ class TourController extends Controller
public function show(Tour $tour)
{
$tour->load('travelType');
$tour->increment('views');
$comments = $tour->comments()
->latest()
->get();
return view('tours.show', compact('tour'));
return view('tours.show', compact('tour','comments'));
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class CommentStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'tour_id' => [
'nullable',
'exists:tours,id',
'required_without:flight_id',
],
'flight_id' => [
'nullable',
'exists:flights,id',
'required_without:tour_id',
],
'rating' => [
'required',
'integer',
'min:1',
'max:5',
],
'comment' => [
'nullable',
'string',
'max:1000',
],
];
}
}