Skip to content

Commit

Permalink
Show currencies on register page
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Oct 23, 2023
1 parent e171927 commit c7a3779
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
17 changes: 17 additions & 0 deletions app/Http/Controllers/Api/CurrencyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\CurrencyResource;
use App\Models\Currency;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;

class CurrencyController extends Controller
{
public function __invoke(): AnonymousResourceCollection
{
return CurrencyResource::collection(Currency::all());
}
}
18 changes: 18 additions & 0 deletions app/Http/Resources/CurrencyResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class CurrencyResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'symbol' => $this->symbol,
];
}
}
3 changes: 3 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Helper;
use App\Models\Space;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\ServiceProvider;
use Auth;

Expand All @@ -26,6 +27,8 @@ public function boot()
'versionNumber' => $versionNumber
]);
});

JsonResource::withoutWrapping();
}

public function register()
Expand Down
21 changes: 19 additions & 2 deletions resources/assets/js/prototype/screens/Register.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<script setup>
//
import axios from 'axios';
import { onMounted, ref } from 'vue';
const currencies = ref([]);
const fetchCurrencies = () => {
axios
.get('http://localhost:8000/api/currencies')
.then(response => currencies.value = response.data);
};
onMounted(() => {
fetchCurrencies();
});
</script>

<template>
Expand All @@ -23,7 +36,11 @@
</div>
<div>
<label class="block mb-1 text-sm text-gray-700">Currency</label>
<input class="w-full px-3 py-2 text-sm border rounded-md" type="text" />
<select class="w-full px-3 py-2 text-sm border rounded-md appearance-none">
<option v-for="currency in currencies">
<span v-html="currency.name + ' (' + currency.symbol + ')'"></span>
</option>
</select>
</div>
<button class="w-full py-2.5 hover:bg-blue-600 transition text-sm bg-blue-500 text-white rounded-md">Register</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

use Illuminate\Http\Request;

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

0 comments on commit c7a3779

Please sign in to comment.