samedi 22 octobre 2016

Laravel query variable as string

What i am doing here might be stupid but i am newbie to laravel, I am applying search filters for database using a query. Query is being built using javascript and being passed to laravel function. E.g.

window.open("/filterResults?types="+types);
//types contains a string like "international#global#europe#  etc

Now in Controller i am getting that string types and exploding it to make a query like this

    $tquery = "Where('type',".$typesArray[0].")";
    for($offset=1; $offset < count($typesArray); $offset++) {
        $tquery .= "->orWhere('type', ".$typesArray[$offset].")";
    }

and executing query like this

$firms = Firm::$tquery->get();

it gives me error

Access to undeclared static property: App\Firm::$tquery

How can i do what i want to.

PS. types are checkboxes some of them can be checked or all.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire