skip to Main Content

I am using this Query.

Safety::with( ['imageName'] )->where( ['property_id', '=', $property->property_id ], ['unit_id', '=', $property->unit_id ],['type','=', 'gas' ])->latest()->first();

I am getting error SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' .

Is there any issue in the Query ?

2

Answers


  1. The issue is in your where clause. Merge it into one array and try.

    Safety::with(['imageName'])
        ->where([
            ['property_id', '=', $property->property_id],
            ['unit_id', '=', $property->unit_id],
            ['type', '=', 'gas']
        ])
        ->latest()
        ->first();
    

    Or add individually like this.

    Safety::with(['imageName'])
        ->where('property_id', '=', $property->property_id)
        ->where('unit_id', '=', $property->unit_id)
        ->where('type', '=', 'gas')
        ->latest()
        ->first();
    
    Login or Signup to reply.
  2. Variant 1

    Safety::with(['imageName'])
        ->where([
            'property_id' => $property->property_id,
            'unit_id' => $property->unit_id,
            'type' => 'gas'
        ])
        ->latest()
        ->first();
    

    Variant 2

    Safety::with(['imageName'])
        ->where('property_id', '=', $property->property_id)
        ->where('unit_id', '=', $property->unit_id)
        ->where('type', '=', 'gas')
        ->latest()
        ->first();
    

    Variant 3

    Safety::with(['imageName'])
        ->wherePropertyId($property->property_id)
        ->whereUnitId($property->unit_id)
        ->whereType('gas')
        ->latest()
        ->first();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search