From 3cfa2e3513164e6a792e66efb0a38e34b514f4c5 Mon Sep 17 00:00:00 2001 From: Jaroslav Drzik Date: Tue, 5 Dec 2023 21:49:32 +0100 Subject: [PATCH] Basic search --- .../Controllers/IkeaProductsController.php | 17 +++++++++ app/Models/IkeaProducts.php | 35 +++++++++++++++++++ lang/id.json | 3 +- resources/js/Pages/IkeaRoot.vue | 34 +++++++++++++++--- routes/web.php | 2 ++ 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 app/Http/Controllers/IkeaProductsController.php create mode 100644 app/Models/IkeaProducts.php diff --git a/app/Http/Controllers/IkeaProductsController.php b/app/Http/Controllers/IkeaProductsController.php new file mode 100644 index 0000000..a6d0f12 --- /dev/null +++ b/app/Http/Controllers/IkeaProductsController.php @@ -0,0 +1,17 @@ + 3) { + return $this->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%')->get(); + } else { + return []; + } + } +} diff --git a/lang/id.json b/lang/id.json index 7fc506f..4dcc963 100644 --- a/lang/id.json +++ b/lang/id.json @@ -98,5 +98,6 @@ "referenceerror: assignment to undeclared variable acntry": "ReferenceError: assignment to undeclared variable aCntry", "referenceerror: _code is not defined": "ReferenceError: _code is not defined", "referenceerror: acntry is not defined": "ReferenceError: aCntry is not defined", - "error: request failed with status code 500": "Error: Request failed with status code 500" + "error: request failed with status code 500": "Error: Request failed with status code 500", + "error: ziggy error: 'item' parameter is required for route 'products.search'.": "Error: Ziggy error: 'item' parameter is required for route 'products.search'." } \ No newline at end of file diff --git a/resources/js/Pages/IkeaRoot.vue b/resources/js/Pages/IkeaRoot.vue index 3cc4556..1d3d8b2 100644 --- a/resources/js/Pages/IkeaRoot.vue +++ b/resources/js/Pages/IkeaRoot.vue @@ -26,11 +26,13 @@ const ccountry_list = ref(['TEST']); const selected = ref(null); const article = ref(''); const hrates = ref([ - { text: "Currency", value: "currency", sortable: true}, - { text: "Country", value: "country_name", sortable: true}, - { text: "Rate", value: "rate", sortable: true} + { text: "Currency", value: "currency", sortable: true }, + { text: "Country", value: "country_name", sortable: true }, + { text: "Rate", value: "rate", sortable: true } ]); const rates = ref([]); +const options_items = ref([]); +const selected_item = ref(null); const options = { region: 150, @@ -96,6 +98,30 @@ const fetch_rates = async () => { } } +const async_search = async (item) => { + try { + if (item.length > 4) { + const response = await axios.get(route('products.search',item)); + options_items.value = response.data.map((i) => { return { "item": i.name, "desc": i.typeName, "img": i.mainImageUrl } }); + console.log("VALUES=", options_items.value); + } + } catch (e) { + const response = await Swal.fire({ + title: __('are you want to try again') + '?', + text: __(`${e}`), + icon: 'question', + showCancelButton: true, + showCloseButton: true, + }) + + response.isConfirmed && fetch() + } +} + +function customLabel({item, desc}) { + //console.log(item); + return `${item} - ${desc}` ; +} const headers = ref([ { text: "Id", value: "id", sortable: true }, { text: "Country", value: "country", sortable: true }, @@ -158,7 +184,7 @@ onMounted(fetch_rates); Zadaj polozku
- +
diff --git a/routes/web.php b/routes/web.php index b80f9da..25f1042 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,6 +5,7 @@ use Inertia\Inertia; use App\Http\Controllers\CountryCodeController; use App\Http\Controllers\CountryCompareController; use App\Http\Controllers\CurrencyRatesController; +use App\Http\Controllers\IkeaProductsController; /* |-------------------------------------------------------------------------- | Web Routes @@ -24,6 +25,7 @@ Route::get('/ccountry/', [CountryCodeController::class, 'index'])->name('ccountr Route::get('/ccountry/active/', [CountryCodeController::class, 'active'])->name('ccountry.active'); Route::get('/search/{id}',[CountryCompareController::class,'search'])->name('ccompare.search'); Route::get('/rates/', [CurrencyRatesController::class, 'index'])->name('rates.index'); +Route::get('/products/{item}', [IkeaProductsController::class, 'search'])->name('products.search'); Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified'])->group(function () {