diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php new file mode 100644 index 0000000..cc95ded --- /dev/null +++ b/app/Http/Controllers/CommentController.php @@ -0,0 +1,39 @@ +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')); + } +} diff --git a/app/Http/Requests/CommentPostRequest.php b/app/Http/Requests/CommentPostRequest.php new file mode 100644 index 0000000..323554f --- /dev/null +++ b/app/Http/Requests/CommentPostRequest.php @@ -0,0 +1,28 @@ + 'required|integer', + 'commentable_type' => 'required|string|in:tour,flight', + 'body' => 'required|string|max:1000', + ]; + + if (!auth()->check()) { + $rules['guest_name'] = 'required|string|max:150'; + } + + return $rules; + } +} diff --git a/app/Models/Comment.php b/app/Models/Comment.php new file mode 100644 index 0000000..981c74d --- /dev/null +++ b/app/Models/Comment.php @@ -0,0 +1,54 @@ + 'int', + 'commentable_id' => 'int' + ]; + + protected $fillable = [ + 'user_id', + 'guest_name', + 'commentable_id', + 'commentable_type', + 'body' + ]; + + public function commentable() + { + return $this->morphTo(); + } + + public function user() + { + return $this->belongsTo(User::class); + } +} diff --git a/resources/views/dashboard/comments.blade.php b/resources/views/dashboard/comments.blade.php new file mode 100644 index 0000000..ac8d953 --- /dev/null +++ b/resources/views/dashboard/comments.blade.php @@ -0,0 +1,54 @@ +@extends('dashboard.layouts.app') + +@section('title' , 'نظرات من') + + +@section('account-content') + + + + + + +
+
+
+ +
+
+
+ + +@endsection