I want to filter data by using 'like' or '=' but I do not want to expose them directly in the view because it is easy to manipulate form view, this is my render method:
public function render(){
$bc = BC::query();
$bc = $bc->where($this->option, $this->condition,$this->searchString)->get();
return view('livewire.customer', [
'bCs' => $bc,
]);
}
This is my front element, and it will not working when I use the like
.
<select wire:model="condition" class="form-control">
<option value="like">Like</option>
<option value="=">=</option>
</select>
I am not sure that this is the best approach but it's working for me.
public $sign ;
if($this->condition == 'like')
{
$this->sign = '%';
}else if($this->condition == '='){
$this->sign = '';
}else{
$this->sign = '%';
$this->condition = 'like'
}
public function render(){
$bc = BC::query();
$bc = $bc->where($this->option, $this->condition,$this->sign.$this->searchString.$this->sign)->get();
return view('livewire.customer', [
'bCs' => $bc,
]);
}