F
Filament6mo 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
awcodes6mo ago
You’re using a greater than to compare two strings. ‘> stock’ doesn’t make sense.
HeyWeb
HeyWeb6mo ago
return static::getModel()::where('stock_minimo','>',intval('stock'))->count(); Not working
awcodes
awcodes6mo 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 Wink6mo 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
HeyWeb6mo ago
stock_minimo in database is integer
awcodes
awcodes6mo ago
Great but ‘stock’ is a string in your code not an integer. Seems like ‘stock’ should be a variable and not ‘stock’
HeyWeb
HeyWeb6mo ago
OK. Thanks
John Wink
John Wink6mo ago
Nice, you saw for yourself that
::pluck
::pluck
doesn't work but returns more than one number 🙂
HeyWeb
HeyWeb6mo ago
any ideas?
John Wink
John Wink6mo ago
?
HeyWeb
HeyWeb6mo 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
Vp6mo 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 Koch6mo ago
You replied "Ok Thanks" to awcodes explanation. Didn't sound like you need further assistance 😅
HeyWeb
HeyWeb6mo ago
Perfect Vp. Thanks
Want results from more Discord servers?
Add your server