Skip to content

Commit c7a3779

Browse files
Show currencies on register page
1 parent e171927 commit c7a3779

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Http\Resources\CurrencyResource;
7+
use App\Models\Currency;
8+
use Illuminate\Http\Request;
9+
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
10+
11+
class CurrencyController extends Controller
12+
{
13+
public function __invoke(): AnonymousResourceCollection
14+
{
15+
return CurrencyResource::collection(Currency::all());
16+
}
17+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Http\Resources;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\Resources\Json\JsonResource;
7+
8+
class CurrencyResource extends JsonResource
9+
{
10+
public function toArray(Request $request): array
11+
{
12+
return [
13+
'id' => $this->id,
14+
'name' => $this->name,
15+
'symbol' => $this->symbol,
16+
];
17+
}
18+
}

app/Providers/AppServiceProvider.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Helper;
66
use App\Models\Space;
7+
use Illuminate\Http\Resources\Json\JsonResource;
78
use Illuminate\Support\ServiceProvider;
89
use Auth;
910

@@ -26,6 +27,8 @@ public function boot()
2627
'versionNumber' => $versionNumber
2728
]);
2829
});
30+
31+
JsonResource::withoutWrapping();
2932
}
3033

3134
public function register()

resources/assets/js/prototype/screens/Register.vue

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<script setup>
2-
//
2+
import axios from 'axios';
3+
import { onMounted, ref } from 'vue';
4+
5+
const currencies = ref([]);
6+
7+
const fetchCurrencies = () => {
8+
axios
9+
.get('http://localhost:8000/api/currencies')
10+
.then(response => currencies.value = response.data);
11+
};
12+
13+
onMounted(() => {
14+
fetchCurrencies();
15+
});
316
</script>
417

518
<template>
@@ -23,7 +36,11 @@
2336
</div>
2437
<div>
2538
<label class="block mb-1 text-sm text-gray-700">Currency</label>
26-
<input class="w-full px-3 py-2 text-sm border rounded-md" type="text" />
39+
<select class="w-full px-3 py-2 text-sm border rounded-md appearance-none">
40+
<option v-for="currency in currencies">
41+
<span v-html="currency.name + ' (' + currency.symbol + ')'"></span>
42+
</option>
43+
</select>
2744
</div>
2845
<button class="w-full py-2.5 hover:bg-blue-600 transition text-sm bg-blue-500 text-white rounded-md">Register</button>
2946
</div>

routes/api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
use Illuminate\Http\Request;
44

5-
//
5+
Route::get('/currencies', \App\Http\Controllers\Api\CurrencyController::class);

0 commit comments

Comments
 (0)