diff options
Diffstat (limited to 'routes/web.php')
-rw-r--r-- | routes/web.php | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/routes/web.php b/routes/web.php index b130397..9396c11 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,9 @@ <?php use Illuminate\Support\Facades\Route; +use Illuminate\Support\Collection; +use App\Models\Currency; +use App\Models\Rates; /* |-------------------------------------------------------------------------- @@ -14,5 +17,20 @@ use Illuminate\Support\Facades\Route; */ Route::get('/', function () { - return view('welcome'); + + /* + select value, currency_id, relative_id, MAX(updated_at) + from rates + group by (currency_id); + */ + $ratesRaw = DB::table('rates') + ->selectRaw("id, value, currency_id, relative_id, max(`created_at`) as created_at") + ->groupByRaw('currency_id') + ->get(); + + $rates = new Collection(); + foreach($ratesRaw as $r) { + $rates->push(Rates::find($r->id)); + } + return view('welcome', ['currencies' => Currency::all(), 'rates' => $rates]); }); |