Reputation: 15
I do a search with 3 inputs and then input can be empty
i get variables from the front-end
$addressSearch = $request->json()->get('addressSearch');
$typeSearch = $request->json()->get('typeSearch');
$statusSearch = $request->json()->get('statusSearch');
I do this search use the function inside the query
$property = Property::where('id', '1')
->Where(function($query)
{
$query->Where('type',typeSearch)
->orWhere('status',$statusSearch)
->orWhere('street','LIKE',"% $addressSearch}%");
})
->get();
and I get this error:
message: "Undefined property: App\Http\Controllers\PropertyController::$typeSearch
the variable receives the value normally
Upvotes: 0
Views: 246
Reputation: 50767
You have type errors, and you're not passing any variables to the closure function, so they don't exist anyway:
$property = Property::where('id', '1')
->where(function($query) use ($typeSearch, $statusSearch, $addressSearch)
{
$query->where('type',$typeSearch)
->orWhere('status',$statusSearch)
->orWhere('street','LIKE',"%{$addressSearch}%");
})->get();
Upvotes: 1