feat: implement flight show blade and comments flight
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum CommentStatus: int
|
||||
{
|
||||
case PENDING = 0;
|
||||
case APPROVED = 1;
|
||||
case REJECTED = 2;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\CommentPostRequest;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Tour;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
public function storeFlight(CommentPostRequest $request, Flight $flight)
|
||||
{
|
||||
$this->store($request, ['flight_id' => $flight->id]);
|
||||
|
||||
return back()->with('success', 'نظر شما با موفقیت ثبت شد.');
|
||||
}
|
||||
|
||||
public function storeTour(CommentPostRequest $request, Tour $tour)
|
||||
{
|
||||
$this->store($request, ['tour_id' => $tour->id]);
|
||||
|
||||
return back()->with('success', 'نظر شما با موفقیت ثبت شد.');
|
||||
}
|
||||
|
||||
private function store(CommentPostRequest $request, array $relation)
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
Comment::create([
|
||||
...$relation,
|
||||
'user_id' => auth()->id(),
|
||||
'guest_name' => auth()->check() ? null : $data['guest_name'],
|
||||
'guest_email' => auth()->check() ? null : $data['guest_email'],
|
||||
'comment' => $data['comment'],
|
||||
'status' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CommentPostRequest 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 [
|
||||
'rating' => [
|
||||
'required',
|
||||
'integer',
|
||||
'between:1,5',
|
||||
],
|
||||
|
||||
'comment' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:3',
|
||||
'max:1000',
|
||||
],
|
||||
|
||||
'guest_name' => [
|
||||
$isGuest ? 'required' : 'nullable',
|
||||
'string',
|
||||
'max:191',
|
||||
],
|
||||
|
||||
'guest_email' => [
|
||||
$isGuest ? 'required' : 'nullable',
|
||||
'email',
|
||||
'max:191',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+43
-20
@@ -6,40 +6,63 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CommentStatus;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Comment
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int|null $user_id
|
||||
* @property int|null $flight_id
|
||||
* @property int|null $tour_id
|
||||
* @property string|null $guest_name
|
||||
* @property string|null $guest_email
|
||||
* @property string $comment
|
||||
* @property int $status
|
||||
* @property Carbon $created_at
|
||||
*
|
||||
* @property User $user
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @property User|null $user
|
||||
* @property Flight|null $flight
|
||||
* @property Tour|null $tour
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Comment extends Model
|
||||
{
|
||||
protected $table = 'comments';
|
||||
public $timestamps = false;
|
||||
protected $table = 'comments';
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'status' => 'int'
|
||||
];
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
'flight_id' => 'int',
|
||||
'tour_id' => 'int',
|
||||
'status' => CommentStatus::class,
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'comment',
|
||||
'status'
|
||||
];
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'flight_id',
|
||||
'tour_id',
|
||||
'guest_name',
|
||||
'guest_email',
|
||||
'comment',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function flight()
|
||||
{
|
||||
return $this->belongsTo(Flight::class, 'flight_id');
|
||||
}
|
||||
|
||||
public function tour()
|
||||
{
|
||||
return $this->belongsTo(Tour::class, 'tour_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user