I'm trying to create a conditional menu in a datatable. For some records the menu will appear, in other cases it will not. My backend (PHP) sends the following parameters to the frontend:
['field' => 'blocked_at', 'operator' => '!==', 'value' => null]
or
['field' => 'blocked_at', 'operator' => '===', 'value' => null]
So in HTML I call the function
<template x-if="checkConditions(record[action.conditions.field], action.conditions.operator, action.conditions.value)">
<a href="#!" class="dropdown-item" x-on:click="runAction(action, record[action.keyfield])">
<i x-bind:class="action.icon"></i><span x-text="action.label"></span>
</a>
</template>
function in Alpine.js
checkConditions (field, operator, value) {
let condition = `${field} ${operator} ${value} ? true : false`;
return eval(condition);
},
But it doesn't work, I'm getting the error "identifier starts immediately after numeric literal". I don't know why this happens. There is an error in the checkConditions function.
Could you help me solve this challenge?