git commit "Complete today's development"
This commit is contained in:
@@ -10,8 +10,12 @@ class CityController extends Controller
|
||||
//
|
||||
public function getCities($province)
|
||||
{
|
||||
return City::where('province_id', $province)
|
||||
|
||||
$cities = City::where('province_id',$province)
|
||||
->orderBy('name')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return response()->json($cities);
|
||||
|
||||
}}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\FlightSearchRequest;
|
||||
use App\Models\Flight;
|
||||
|
||||
class FlightController extends Controller
|
||||
{
|
||||
public function search(FlightSearchRequest $request)
|
||||
{
|
||||
$filters = $request->validated();
|
||||
|
||||
$flights = Flight::query()
|
||||
->applySearch($filters)
|
||||
->get();
|
||||
|
||||
return view('flights.search', compact('flights'));
|
||||
}
|
||||
|
||||
public function archive()
|
||||
{
|
||||
$flights = Flight::query()
|
||||
->latest()
|
||||
->paginate(12);
|
||||
|
||||
return view('flights.archive', compact('flights'));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,17 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Flight;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
//
|
||||
public function index()
|
||||
{
|
||||
return view('layouts.app');
|
||||
$latestFlights = Flight::query()
|
||||
->latest()
|
||||
->take(6)
|
||||
->get();
|
||||
|
||||
return view('home.index', compact('latestFlights'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class FlightSearchRequest 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
|
||||
{
|
||||
return [
|
||||
'origin' =>
|
||||
[
|
||||
'required',
|
||||
],
|
||||
'destination' =>
|
||||
[
|
||||
'required',
|
||||
],
|
||||
'departure_date' =>
|
||||
[
|
||||
'required',
|
||||
'date',
|
||||
],
|
||||
'passengers' =>
|
||||
[ 'required',
|
||||
'integer',
|
||||
'min:1',
|
||||
],
|
||||
|
||||
]; }
|
||||
}
|
||||
+6
-2
@@ -12,13 +12,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class City
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $provinces
|
||||
* @property string $name
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
*
|
||||
* @property Collection|User[] $users
|
||||
*
|
||||
* @package App\Models
|
||||
@@ -41,4 +41,8 @@ class City extends Model
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
public function province()
|
||||
{
|
||||
return $this->hasMany(Province::class);
|
||||
}
|
||||
}
|
||||
|
||||
+21
-1
@@ -7,11 +7,13 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Flight
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string|null $airline
|
||||
* @property string|null $flight_number
|
||||
@@ -56,4 +58,22 @@ class Flight extends Model
|
||||
'price',
|
||||
'status'
|
||||
];
|
||||
|
||||
#[Scope]
|
||||
public function applySearch(Builder $query, array $filters): void
|
||||
{
|
||||
$query
|
||||
->when($filters['origin'] ?? null, function ($query, $origin) {
|
||||
$query->where('origin', $origin);
|
||||
})
|
||||
->when($filters['destination'] ?? null, function ($query, $destination) {
|
||||
$query->where('destination', $destination);
|
||||
})
|
||||
->when($filters['departure_date'] ?? null, function ($query, $date) {
|
||||
$query->whereDate('departure_date', $date);
|
||||
})
|
||||
->when($filters['passengers'] ?? null, function ($query, $passengers) {
|
||||
$query->where('capacity', '>=', $passengers);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,9 @@ class Province extends Model
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
public function cities()
|
||||
{
|
||||
return $this->hasMany(City::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Province;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -19,6 +20,13 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
\Illuminate\Support\Facades\View::composer('layouts.hero', function ($view) {
|
||||
|
||||
$provinces = Province::orderBy('name')->get();
|
||||
|
||||
$view->with('provinces', $provinces);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Home;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class LatestFlights extends Component
|
||||
{
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*/
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.home.latest-flights');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user