Friday, March 17, 2017

Laravel - operators dont work

I'm new to laravel, and I've been learning a few more things. But now I'm getting a error that I have never seen in plain php. Some operators that I test in the function catalog don't work, while others do. Only the =, != and <> work, while the <, >, >= and <= don't. It gives me: "Illegal operator and value combination"; and also: ->where('Price', '(operator)', null). I have tried "wherenull" but doesnt work. Can anyone help me out on this one? Im using laravel 5.4.

the code:

controller (in this case i have placed ">=" it doesnt work)

function catalog(Request $abc) {
    $categoryesc = $abc->categoryesc;
    $priceesc = $abc->priceesc;
    $categories = DB::table('categories')->pluck('Category', 'id');
    $robots = DB::table('robots')->where('Category_id', $categoryesc)->where('Price', '>=', $priceesc)->get();
    return view('catalog', compact('robots', 'categories'));
}

view

@extends('layouts.layout')
@include('header')

<main>
<div>Choose the category</div>
{!! Form::open(array('method' => 'GET')) !!}
    {!! Form::select('categoryesc', $categories) !!}
    
    {!! Form::submit('Ok') !!}
{!! Form::close() !!}

<div>Choose the model</div>
<b>On this page ( robots)</b>

<div id="area1">
@foreach($robots as $robot)
  {!! Form::open(array('action' => 'RobotController@orders', 'method' =>  'GET')) !!}
  {!! Form::hidden('modelesc', $robot->Model) !!}
  {!! Form::submit($robot->Model) !!}
  {!! Form::close() !!}
@endforeach
</div>

</main>

the full error message is:

InvalidArgumentException in Builder.php line 609: Illegal operator and value combination

Apparent solution

I think that i have solved this: I went to the file at \vendor\laravel\framework\src\illuminate\database\query\builder.php and at line 627 added "<=" (the operator that i want to use). Now its working. Otherwise ill return to this later.



via Adato

Advertisement