The Laravel site has a game for users. And i need to do that if the user loses the game, he is shown a notification that cashback has been credited to his balance. But the code doesn't want to work. This is all I am trying to do in the controller.
My code:
public function crashBets()
{
$game = $this->getGameInController();
$betsLose = Bet::query()->with('user')->where([
['game_id', $game->id],
['is_win', 0]
]);
# Add cashback
$betsLose->get()->each(function($bet) {
# Add cashback
$bet->user->increment(
'cashback', ($bet->bank / 100 ) * 1
);
$this->cashbackNotify();
});
# Update bets
$betsLose->update([
'is_win' => 2,
'multiplier' => $game->multiplier
]);
$bets = $this->getBets();
return $bets;
}
$betsLose success update infromation in database. I try add the function:
public function cashbackNotify()
{
return [
'success' => false,
'message' => 'item_not_found'
];
}
And call it's function in $betsLose->get()->each(function($bet) {, i write $this->cashbackNotify(); but nothing happens. What i did wrong? How i can make it work?