Dynamic naming of get parameters in inertia router I want to make a filter for the records.
I want to make a custom component, with the dynamic naming of get parameters, in inertia router, but it constantly gives me an error. -
RangeError: Maximum call stack size exceede
How to make a successful filter, can you show examples of the implementation of complex filters?
Can you show us what you have now? We would like to help but I doubt anyone wants to write the full code or you
@Sinnbeck
<script setup>
import {NInput, NSelect} from "naive-ui";
import {computed, ref, watch} from "vue";
import {debounce} from "lodash";
import {router} from "@inertiajs/vue3";
const props = defineProps({
typeFilter: String,
options: Array,
paramName: String
})
const model = defineModel();
const dataObject = {
[props.paramName] : model
}
watch(model, (model)=>{
if (props.typeFilter === "select"){
if (model !== "default"){
router.get('/products', dataObject)
}
else {
router.get('/products', dataObject)
}
}
else
{
debounce((model)=>{
router.get('/products',dataObject)
},1000)
}
}
)
</script>
<template>
{{dataObject}}
<div v-if='typeFilter==="input"'>
<n-input class="border w-full" v-model:value="model" placeholder="Поиск..." />
</div>
<div v-if='typeFilter==="select"'>
<n-select size="small" placeholder="Сортировка" v-model:value="model" :options="options"/>
</div>
</template>
<style scoped>
</style>
@Sinnbeck
public function index(Request $request){
$search=request()->query('search');
$priceSort=request()->query('price');
$products = Product::query();
if($search){
$products = $products->where('name','like','%'.$search.'%')
->orWhere('model','like','%'.$search.'%');
}
if ($priceSort){
if ($priceSort=='low'){
$products = $products->orderBy('price');
}
elseif ($priceSort=='high'){
$products = $products->orderBy('price','desc');
}
else{
$products = $products->orderBy('id','desc');
}
}
$products = $products->paginate(10)->withQueryString();
return Inertia::render('Product/Index',['products' => $products, 'filters' => [
'search' => $search,
'priceSort' => $priceSort,
]]);
}
So laravel does not give an error. The error is given by inertia, due to incorrect naming of get parameters.
Please sign in or create an account to participate in this conversation.