Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lara_Love's avatar

search form

You know choosing a house for rent. A person who does not care about the price does not enter a number and the field remains empty. Maybe only the elevator is important to him, and in the search, he finds items with an elevator, so the rest of the fields remain empty. we search form is

   <form action="{{ route('rentsearch') }}" method="GET">
                        @csrf
                    <input type="text" name="thumbnail" placeholder="Street" class="form-control"><br>
                    <input type="number" name="pish" placeholder="Max pish" class="form-control"><br>
                    <input type="number" name="mah" placeholder="Max month" class="form-control"><br>
                    <input type="number" name="metraj" placeholder="Max meter" class="form-control"><br>
                    <input type="number" name="bedroom" placeholder="Max bedroom's" class="form-control">
                     <input class="form-check-input" type="checkbox" name="parking" id="parking">
                     <input class="form-check-input" type="checkbox" name="elv" id="elv">
                      <input class="form-check-input" type="checkbox" name="storeroom" id="storeroom">
 					<button type="submit" class="btn btn-primary col">Search</button>
   </form>

our controller

  $dat = Rent::query()
            ->when($request->boolean('parking'), fn($query, $value) => $query->where('parking', $value))
            ->when($request->boolean('elv'), fn($query, $value) => $query->where('elv', $value))
            ->when($request->boolean('storeroom'), fn($query, $value) => $query->where('storeroom', $value))
            ->when($request->input('street'), fn($query, $value) => $query->where('street', 'LIKE', "%{$value}%"))
            ->when($request->input('pish'), fn($query, $value) => $query->where('pish', '<=', $value))
            ->when($request->input('mah'), fn($query, $value) => $query->where('mah', '<=', $value))
            ->when($request->input('bedroom'), fn($query, $value) => $query->where('bedroom', '<=', $value))
            ->when($request->input('metraj'), fn($query, $value) => $query->where('metraj', '<=', $value))
//->get();
            ->dd();
        $dat = Rent::where($dat)->get();
        return view('front.house.rentres',

and our error is

"select * from `rents` where `pish` <= ?" // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:3754

array:1 [▼ // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:3754
  0 => "1000"
]

0 likes
17 replies
Lara_Love's avatar

@Sinnbeck I had to look for answers there between the conversations. And it was very crowded. I closed it and created a new question.

Sinnbeck's avatar

Ok so where is the error? You are posting the output of a dd() not an error?

Lara_Love's avatar

@Sinnbeck

 SQLSTATE[42S22]: Column not found: 1054 Unknown column '[{"id"?,"user_id"?,"project_id"?,"house_id"?,"title":"\u06a9\u0631\u0645\u0627\u0646","pish"?,"mah"?,"desc":"<p>\u0633\u0631\u0648\u06cc\u0633 \u0628\u0647\u062f\u0627\u0634\u062a\u06cc\u0633\' in 'where clause'

select
  *
from
  `rents`
where
  `[{"id":3,"user_id":1,"project_id":1,"house_id":2,"title":
Lara_Love's avatar

@Sinnbeck I found the button, but it seems that the internet speed does not allow it to work can you use this link . this link is on share page ? https://flareapp.io/docs/ignition-for-laravel/sharing-errors i change one word and this is error

SQLSTATE[42S22]: Column not found: 1054 Unknown column '[]' in 'where clause'

select
  *
from
  `rents`
where
  `[]` is null

and when i use dd now

"select * from `rents` where `thumbnail` LIKE ? and `pish` <= ?" // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:3754

array:2 [▼ // vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php:3754
  0 => "%love%"
  1 => "1000"
]

Lara_Love's avatar

@Sinnbeck this is ok ?

 $dat = Rent::query()
            ->when($request->boolean('parking'), fn($query, $value) => $query->where('parking', $value))
            ->when($request->boolean('elv'), fn($query, $value) => $query->where('elv', $value))
            ->when($request->boolean('storeroom'), fn($query, $value) => $query->where('storeroom', $value))
            ->when($request->input('thumbnail'), fn($query, $value) => $query->where('thumbnail', 'LIKE', "%{$value}%"))
            ->when($request->input('pish'), fn($query, $value) => $query->where('pish', '<=', $value))
            ->when($request->input('mah'), fn($query, $value) => $query->where('mah', '<=', $value))
            ->when($request->input('bedroom'), fn($query, $value) => $query->where('bedroom', '<=', $value))
            ->when($request->input('metraj'), fn($query, $value) => $query->where('metraj', '<=', $value))
->get();
        $dat = Rent::where($dat)->get();
        return view('front.house.
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@LoverToHelp You are using the model as the query for another model??

  $dat = Rent::query()
            ->when($request->boolean('parking'), fn($query, $value) => $query->where('parking', $value))
            ->when($request->boolean('elv'), fn($query, $value) => $query->where('elv', $value))
            ->when($request->boolean('storeroom'), fn($query, $value) => $query->where('storeroom', $value))
            ->when($request->input('street'), fn($query, $value) => $query->where('street', 'LIKE', "%{$value}%"))
            ->when($request->input('pish'), fn($query, $value) => $query->where('pish', '<=', $value))
            ->when($request->input('mah'), fn($query, $value) => $query->where('mah', '<=', $value))
            ->when($request->input('bedroom'), fn($query, $value) => $query->where('bedroom', '<=', $value))
            ->when($request->input('metraj'), fn($query, $value) => $query->where('metraj', '<=', $value))
            ->get();
//        $dat = Rent::where($dat)->get(); //this makes no sense. as you already have the data  :)
        return view('front.house.rentres',
Lara_Love's avatar

@Sinnbeck Yes that is right . I also looked carefully now and saw why I wrote like this. I hope one day I will come to the site like you and solve all the questions

Lara_Love's avatar

@Sinnbeck I have a lot of problems with queries. I study with the w3school website, but when I get to solving the problem, every time I look, I see everything new.

Sinnbeck's avatar

@LoverToHelp Its never too late to learn :) But I learned a lot when I was hired as a junior developer

Lara_Love's avatar

@Sinnbeck I was supposed to work for a company, but my level was higher than theirs. I saw that I was not making progress / I gave up. Here, a person who has money and a relationship with managers participates and employs some people. Since my field of study is construction, in a few months I will be both a site designer and a construction job

Sinnbeck's avatar

@LoverToHelp Its good to diversity. I worked in a callcenter for 13 years before becoming a programmer :)

Please or to participate in this conversation.