feat: implement currency rates tracking with models, migrations and views

This commit is contained in:
2025-05-24 05:59:12 +03:00
parent 72b4eff3ee
commit b19748ef20
21 changed files with 690 additions and 361 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers;
use App\Models\City;
use App\Models\Rate;
class RateController extends Controller
{
public function __invoke()
{
$supportedCities = City::query()
->whereIn('name', City::supportedCities())
->get()
->sortByDesc(fn ($city) => $city->name === 'sanaa')
->values();
$rates = Rate::query()
->with('currency', 'city')
->orderBy('city_id', 'asc')
->orderBy('currency_id', 'asc')
->orderBy('date', 'desc')
->get()
->groupBy(fn ($rate) => $rate->city_id.'-'.$rate->currency_id)
->map(fn ($group) => $group->first())
->groupBy('city_id');
return view('rates', [
'rates' => $rates,
'supportedCities' => $supportedCities,
]);
}
}