Im learning Laravel, and still a lot to learn. Been practising lately, and now im a situation where i want in the same page to make a query of the table "robots" based on a choice of a category and then if i want, make a new query based on that choice AND adding a price range choice. But its getting a error: "array_key_exists() expects parameter 2 to be array, integer given". I dont even know exactly where is the error. Can anyone help?
The laravel version is 5.4. The tables in this case are: robots, categories
this is the code:
controller
function catalog(Request $request) {
$categories = DB::table('categories')->pluck('Category', 'id');
$categoryesc = $request->categoryesc;
$robots = DB::table('robots')->where('Category_id', $categoryesc)->get();
$priceesc = $request->priceesc;
$robots2 = DB::table('robots')->where('Category_id', $categoryesc AND 'Price', '<=', $priceesc)->get();
return view('catalog', compact('robots', 'categories'));
}
Catalog.php
@extends('layouts.layout')
@include('header')
<main>
<h1>Catalog</h1>
<div>Choose the category</div>
{!! Form::open(array('method' => 'GET')) !!}
{!! Form::select('categoryesc', ['Category', $categories], array('onchange' => 'chcat()')) !!}
{!! Form::close() !!}
<div>Choose the price</div>
{!! Form::open(array('method' => 'GET')) !!}
{!! Form::selectRange('priceesc', 100, 200, 300, 400, 500, array('onchange' => 'chpri()')) !!}
{!! 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>
<div id="area2">
@foreach($robots2 as $robot2)
{!! Form::open(array('action' => 'RobotController@orders', 'method' => 'GET')) !!}
{!! Form::hidden('modelesc', $robot->Model) !!}
{!! Form::submit($robot->Model) !!}
{!! Form::close() !!}
@endforeach
</div>
</main>
layout.blade (where i place the jquery)
$('#categoryesc').on('change', function chcat(){
$(this).closest('form').submit();
});
$('#priceesc').on('change', function chpri(){
$(this).closest('form').submit();
});
via Adato