F
Filament7mo ago
HeyWeb

getNavigationBadge()

This function is not working for me, what could be the reason? public static function getNavigationBadge(): ?string { return static::getModel()::where('stock_minimo','>','stock')->count(); }
No description
Solution:
This is what you need whereColumn https://laravel.com/docs/11.x/queries#additional-where-clauses ```php public static function getNavigationBadge(): ?string { return static::getModel()::whereColumn('stock_minimo', '<', 'stock')->count();...
Jump to solution
14 Replies
awcodes
awcodes7mo ago
You’re using a greater than to compare two strings. ‘> stock’ doesn’t make sense.
HeyWeb
HeyWebOP7mo ago
return static::getModel()::where('stock_minimo','>',intval('stock'))->count(); Not working
awcodes
awcodes7mo ago
Right but what is stock_minimo’s field type in the database. You’re code is saying to return records where ‘stock_minimo’ > ‘stock’, but ‘stock’ is a string and not mathematically comparable.
John Wink
John Wink7mo ago
public static function getNavigationBadge(): ?string
{
return static::getModel()::where('stock_minimo','>',100)->count();
}
public static function getNavigationBadge(): ?string
{
return static::getModel()::where('stock_minimo','>',100)->count();
}
HeyWeb
HeyWebOP7mo ago
stock_minimo in database is integer
awcodes
awcodes7mo ago
Great but ‘stock’ is a string in your code not an integer. Seems like ‘stock’ should be a variable and not ‘stock’
HeyWeb
HeyWebOP7mo ago
OK. Thanks
John Wink
John Wink7mo ago
Nice, you saw for yourself that
::pluck
::pluck
doesn't work but returns more than one number 🙂
HeyWeb
HeyWebOP7mo ago
any ideas?
John Wink
John Wink7mo ago
?
HeyWeb
HeyWebOP7mo ago
I want to control the products that are with minimum_stock, but the following function does not work for me public static function getNavigationBadge(): ?string { return static::getModel()::where('stock_minimo','<','stock')->count(); }
Solution
Vp
Vp7mo ago
This is what you need whereColumn https://laravel.com/docs/11.x/queries#additional-where-clauses
public static function getNavigationBadge(): ?string
{
return static::getModel()::whereColumn('stock_minimo', '<', 'stock')->count();
}
public static function getNavigationBadge(): ?string
{
return static::getModel()::whereColumn('stock_minimo', '<', 'stock')->count();
}
Dennis Koch
Dennis Koch7mo ago
You replied "Ok Thanks" to awcodes explanation. Didn't sound like you need further assistance 😅
HeyWeb
HeyWebOP7mo ago
Perfect Vp. Thanks
Want results from more Discord servers?
Add your server