feat(tour): implement tour details page with comments system and dynamic sidebar
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum CommentStatus:int
|
||||
{
|
||||
case PENDING= 0;
|
||||
case CONFIRMED= 1;
|
||||
case REJECTED= 2;
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::PENDING => 'در انتظار',
|
||||
self::CONFIRMED => 'تایید شده',
|
||||
self::REJECTED => 'رد شده',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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', 'ثبت نظر با خطا مواجه شد.');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Tour;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TourCommentStoreRequest 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
|
||||
{
|
||||
$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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user