#Laravel Eloquent where query not returning any results

11 messages · Page 1 of 1 (latest)

pallid sierra
#

I'm running the following query:

$test_products = Product::where('metal_code', "=", "gold")->get();

That should be giving me one, single result, as my products table has one entry with a metal_code of "gold", but it's not. Any ideas?

Here's my model:

class Product extends Model
{
...
protected $fillable = ['name', 'user_id', 'brand_id', 'category_id', 'created_by', 'slug', 'price',
'is_metals_dev', 'metal_code', 'purchase_cost', 'percent_markup', 'last_price_update', 'barcode',
'video_provider', 'video_url', 'current_stock', 'minimum_order_quantity', 'is_approved', 'is_catalog',
'external_link', 'is_refundable', 'cash_on_delivery', 'attribute_sets','images', 'meta_image', 'colors',
'selected_variants', 'selected_variants_ids', 'contact_info','status'
];
...
}

sterile terrace
#

Show us your table?

#

What does Product::count(); return?

#

Is it connecting to the correct database?

pallid sierra
#

Yes, it returns products in general. One sec...

#

It's just that field which it's not handling properly. It's a field I recently added to the table.

#

Hmm...this is weird. Product::count() returns 1, even though there are FIVE products in the db.

#

Derp. I think my client has been monkeying with stuff. Looks like he unpublished a bunch of products.

#

Now it seems to be working...sort of. Looks like is_deleted = 0 but deleted_at having a date, still means the products are deleted...

#

Even if status=published.

#

Fixed that, but weird.