0

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

2
  • 3
    typeSearch in line 4 should have $ sign, also check that which line error refer to Commented Apr 3, 2020 at 16:56
  • yes, have but keep sending me Undefined variable: Commented Apr 3, 2020 at 17:04

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.