Basic search
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
17
app/Http/Controllers/IkeaProductsController.php
Normal file
17
app/Http/Controllers/IkeaProductsController.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
use App\Models\IkeaProducts;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Client\Pool;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use PhpParser\Node\Expr\Cast\String_;
|
||||||
|
|
||||||
|
class IkeaProductsController extends Controller
|
||||||
|
{
|
||||||
|
public function search(Request $request, string $item)
|
||||||
|
{
|
||||||
|
return IkeaProducts::search($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Models/IkeaProducts.php
Normal file
35
app/Models/IkeaProducts.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class IkeaProducts extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $table = 't_ikea_products';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = null;
|
||||||
|
/**
|
||||||
|
* Indicates if the model's ID is auto-incrementing.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected function search($item)
|
||||||
|
{
|
||||||
|
if (strlen($item) > 3) {
|
||||||
|
return $this->where('typeName', 'LIKE', '%' . $item . '%')->orWhere('name', 'LIKE', '%' . $item . '%')->get();
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,5 +98,6 @@
|
|||||||
"referenceerror: assignment to undeclared variable acntry": "ReferenceError: assignment to undeclared variable aCntry",
|
"referenceerror: assignment to undeclared variable acntry": "ReferenceError: assignment to undeclared variable aCntry",
|
||||||
"referenceerror: _code is not defined": "ReferenceError: _code is not defined",
|
"referenceerror: _code is not defined": "ReferenceError: _code is not defined",
|
||||||
"referenceerror: acntry is not defined": "ReferenceError: aCntry 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'."
|
||||||
}
|
}
|
||||||
@@ -26,11 +26,13 @@ const ccountry_list = ref(['TEST']);
|
|||||||
const selected = ref(null);
|
const selected = ref(null);
|
||||||
const article = ref('');
|
const article = ref('');
|
||||||
const hrates = ref([
|
const hrates = ref([
|
||||||
{ text: "Currency", value: "currency", sortable: true},
|
{ text: "Currency", value: "currency", sortable: true },
|
||||||
{ text: "Country", value: "country_name", sortable: true},
|
{ text: "Country", value: "country_name", sortable: true },
|
||||||
{ text: "Rate", value: "rate", sortable: true}
|
{ text: "Rate", value: "rate", sortable: true }
|
||||||
]);
|
]);
|
||||||
const rates = ref([]);
|
const rates = ref([]);
|
||||||
|
const options_items = ref([]);
|
||||||
|
const selected_item = ref(null);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
region: 150,
|
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([
|
const headers = ref([
|
||||||
{ text: "Id", value: "id", sortable: true },
|
{ text: "Id", value: "id", sortable: true },
|
||||||
{ text: "Country", value: "country", sortable: true },
|
{ text: "Country", value: "country", sortable: true },
|
||||||
@@ -158,7 +184,7 @@ onMounted(fetch_rates);
|
|||||||
<span class="font-extrabold font-mono">Zadaj polozku</span>
|
<span class="font-extrabold font-mono">Zadaj polozku</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<SearchInput v-model="article"></SearchInput>
|
<multiselect v-model="selected_item" label="item" track-by="item" :custom-label="customLabel" placeholder="Find item" :searchable="true" :options="options_items" @search-change="async_search"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-5">
|
<div class="mt-5">
|
||||||
<EasyTable :rows-per-page=10 :headers="headers" :items="items"></EasyTable>
|
<EasyTable :rows-per-page=10 :headers="headers" :items="items"></EasyTable>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use Inertia\Inertia;
|
|||||||
use App\Http\Controllers\CountryCodeController;
|
use App\Http\Controllers\CountryCodeController;
|
||||||
use App\Http\Controllers\CountryCompareController;
|
use App\Http\Controllers\CountryCompareController;
|
||||||
use App\Http\Controllers\CurrencyRatesController;
|
use App\Http\Controllers\CurrencyRatesController;
|
||||||
|
use App\Http\Controllers\IkeaProductsController;
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Web Routes
|
| 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('/ccountry/active/', [CountryCodeController::class, 'active'])->name('ccountry.active');
|
||||||
Route::get('/search/{id}',[CountryCompareController::class,'search'])->name('ccompare.search');
|
Route::get('/search/{id}',[CountryCompareController::class,'search'])->name('ccompare.search');
|
||||||
Route::get('/rates/', [CurrencyRatesController::class, 'index'])->name('rates.index');
|
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 () {
|
Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified'])->group(function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user