feat:complete flight blade and controller and enum
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum FlightStatus: int
|
||||||
|
{
|
||||||
|
case DISABLE = 0;
|
||||||
|
case ENABLE = 1;}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Enums\CommentStatus;
|
||||||
|
use App\Enums\FlightStatus;
|
||||||
|
use App\Models\Flight;
|
||||||
|
use Hekmatinasser\Verta\Verta;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Morilog\Jalali\Jalalian;
|
||||||
|
|
||||||
|
class FlightController extends Controller
|
||||||
|
{
|
||||||
|
public function index(Request $request) {
|
||||||
|
|
||||||
|
$passengers =
|
||||||
|
$request->input('adult', 0) +
|
||||||
|
$request->input('children', 0);
|
||||||
|
|
||||||
|
$flights = Flight::query()
|
||||||
|
->where('status', FlightStatus::ENABLE)
|
||||||
|
->applyFilter()
|
||||||
|
->when($request->filled('from-destination'), function (Builder $query) use ($request) {
|
||||||
|
$query->whereHas('departureAirport.city', function (Builder $query) use ($request) {
|
||||||
|
$query->where('name', 'LIKE', '%' . $request->input('from-destination') . '%');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
->when($request->filled('to-destination'), function (Builder $query) use ($request) {
|
||||||
|
$query->whereHas('arrivalAirport.city', function (Builder $query) use ($request) {
|
||||||
|
$query->where('name', 'LIKE', '%' . $request->input('to-destination') . '%');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
// ->when($request->filled('journey-date'), function (Builder $query) use ($request) {
|
||||||
|
// $date = Verta::parse($request->input('journey-date'))
|
||||||
|
// ->formatGregorian('Y-m-d');
|
||||||
|
//
|
||||||
|
// $query->whereDate('departure_time', $date);
|
||||||
|
// })
|
||||||
|
->when($passengers > 0, function (Builder $query) use ($passengers) {
|
||||||
|
$query->where('capacity', '>=', $passengers);
|
||||||
|
})
|
||||||
|
->with([
|
||||||
|
'departureAirport.city',
|
||||||
|
'arrivalAirport.city',
|
||||||
|
'airline',
|
||||||
|
'file',
|
||||||
|
])
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->paginate(12);
|
||||||
|
|
||||||
|
return view('flights.index', compact('flights'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(Flight $flight)
|
||||||
|
{
|
||||||
|
abort_if($flight->status !== FlightStatus::ENABLE->value, 404);
|
||||||
|
|
||||||
|
$flight->increment('views');
|
||||||
|
|
||||||
|
$flight->load([
|
||||||
|
'departureAirport.city',
|
||||||
|
'arrivalAirport.city',
|
||||||
|
'airline',
|
||||||
|
'file',
|
||||||
|
'comments' => function ($query) {
|
||||||
|
$query->where('status', CommentStatus::APPROVED)
|
||||||
|
->with('user')
|
||||||
|
->orderByDesc('created_at');
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return view('flights.show', compact('flight'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
<div class="col-md-6 col-lg-3">
|
||||||
|
<div class="flight-item">
|
||||||
|
<div class="flight-img">
|
||||||
|
<img src="assets/img/flight/01.jpg" alt>
|
||||||
|
<a href="#" class="add-wishlist"><i class="far fa-heart"></i></a>
|
||||||
|
</div>
|
||||||
|
<div class="flight-content">
|
||||||
|
<div class="flight-title">
|
||||||
|
<div class="flight-title-info">
|
||||||
|
<img src="assets/img/flight/airline-1.png" alt>
|
||||||
|
<h4><a href="#">{{ $flight->departureAirport->city->name }}<i class="far fa-exchange"></i> {{ $flight->arrivalAirport->city->name }} </a></h4>
|
||||||
|
</div>
|
||||||
|
<p class="flight-date"><i class="far fa-calendar-days"></i>{{ $flight->departure_time->toJalali()->format('Y/m/d H:i') }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="flight-bottom">
|
||||||
|
<div class="flight-price">
|
||||||
|
از <span> {{ number_format($flight->price) }} تومان </span>
|
||||||
|
</div>
|
||||||
|
<div class="flight-text-btn">
|
||||||
|
<a href="{{ route('flights.show', $flight->id) }}">نمایش جزئیات <i class="fas fa-arrow-left"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
Reference in New Issue
Block a user