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