diff --git a/app/Enums/CommentStatus.php b/app/Enums/CommentStatus.php new file mode 100644 index 0000000..f72c11c --- /dev/null +++ b/app/Enums/CommentStatus.php @@ -0,0 +1,19 @@ + 'در انتظار', + self::CONFIRMED => 'تایید شده', + self::REJECTED => 'رد شده', + }; + } +} diff --git a/app/Http/Controllers/Account/ProfileController.php b/app/Http/Controllers/Account/ProfileController.php index 57d412b..d043430 100644 --- a/app/Http/Controllers/Account/ProfileController.php +++ b/app/Http/Controllers/Account/ProfileController.php @@ -25,5 +25,19 @@ class ProfileController extends Controller return response()->json($cities); } + public function comments() + { + $comments = auth()->user() + ->comments() + ->with([ + 'tour', + 'flight' + ]) + ->orderByDesc('created_at') + ->paginate(10); + + return view('account.comments' , compact('comments')); + } + } diff --git a/app/Http/Controllers/TourController.php b/app/Http/Controllers/TourController.php index f0d0eac..5f05379 100644 --- a/app/Http/Controllers/TourController.php +++ b/app/Http/Controllers/TourController.php @@ -2,6 +2,9 @@ namespace App\Http\Controllers; +use App\Enums\CommentStatus; +use App\Http\Requests\Tour\TourCommentStoreRequest; +use App\Models\Comment; use App\Models\Tour; use Illuminate\Http\Request; @@ -28,8 +31,40 @@ class TourController extends Controller public function show(Tour $tour) { $title= 'جزئیات تور'; - $tour->load(['file', 'originCity', 'city', 'tourDepartures', 'comments.user']); + $tour->load([ + 'file', + 'originCity', + 'city', + 'tourDepartures', + 'comments' => function ($query) { + $query->latest(); + }, + 'comments.user' + ]); return view('tours.show', compact('title' , 'tour')); } + public function commentStore(TourCommentStoreRequest $request, Tour $tour) + { + + try { + Comment::create([ + 'tour_id' => $tour->id, + 'user_id' => auth()->id(), + 'parent_id' => $request->parent_id, + 'guest_name' => auth()->check() ? null : $request->guest_name, + 'guest_email' => auth()->check() ? null : $request->guest_email, + 'content' => $request->content, + 'status' => CommentStatus::PENDING, + ]); + + return back()->with('success', 'نظر شما با موفقیت ثبت شد.'); + } catch (\Exception $e) { + return back() + ->withInput() + ->with('error', 'ثبت نظر با خطا مواجه شد.'); + + } + } + } diff --git a/app/Http/Requests/Tour/TourCommentStoreRequest.php b/app/Http/Requests/Tour/TourCommentStoreRequest.php new file mode 100644 index 0000000..8e962dd --- /dev/null +++ b/app/Http/Requests/Tour/TourCommentStoreRequest.php @@ -0,0 +1,54 @@ +|string> + */ + public function rules(): array + { + $isGuest = ! auth()->check(); + + return [ + 'guest_name' => [ + $isGuest ? 'required' : 'nullable', + 'string', + 'max:255', + ], + + 'guest_email' => [ + $isGuest ? 'required' : 'nullable', + 'email', + 'max:255', + ], + + 'content' => [ + 'required', + 'string', + 'min:5', + 'max:2000', + ], + + 'parent_id' => [ + 'nullable', + 'integer', + 'exists:comments,id', + ], + ]; + } +} diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 0decada..3173917 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -6,13 +6,14 @@ namespace App\Models; +use App\Enums\CommentStatus; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Comment - * + * * @property int $id * @property int|null $user_id * @property int|null $admin_id @@ -26,7 +27,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property Carbon $created_at * @property Carbon $updated_at * @property string|null $deleted_at - * + * * @property Flight|null $flight * @property Tour|null $tour * @property User|null $user @@ -46,7 +47,7 @@ class Comment extends Model 'tour_id' => 'int', 'flight_id' => 'int', 'parent_id' => 'int', - 'status' => 'int' + 'status' => CommentStatus::class ]; protected $fillable = [ diff --git a/resources/views/account/comments.blade.php b/resources/views/account/comments.blade.php new file mode 100644 index 0000000..43a11a1 --- /dev/null +++ b/resources/views/account/comments.blade.php @@ -0,0 +1,100 @@ +@extends('account.layouts.app') + +@section('account-content') +
+@endsection diff --git a/resources/views/tours/partials/sidebar.blade.php b/resources/views/tours/partials/sidebar.blade.php index b6d1455..e76357f 100644 --- a/resources/views/tours/partials/sidebar.blade.php +++ b/resources/views/tours/partials/sidebar.blade.php @@ -1,16 +1,16 @@