blob: c7be55c72683fd75fdd0c5172405bfaa20950ac7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Collection;
use App\Models\Currency;
use App\Models\Rates;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
/*
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) {
$rate = Rates::find($r->id);
if($rate->currency->name != "Bitcoin") {
$rates->push($rate);
}
}
return view('welcome', ['currencies' => Currency::all(), 'rates' => $rates]);
});
|