class Illuminate / Support / Lottery
You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.

Lottery

Properties

protected

$chances int|float

The number of expected wins.

Default: null
protected

$outOf int|null

The number of potential opportunities to win.

Default: null
protected

$winner null|callable

The winning callback.

Default: null
protected

$loser null|callable

The losing callback.

Default: null
protected static

$resultFactory callable|null

The factory that should be used to generate results.

Default: null

Methods

public

__construct ( $chances , $outOf ) : void

Create a new Lottery instance.

Parameters

  • $chances int|float
  • $outOf int|null
public static

odds ( $chances , $outOf ) : static

Create a new Lottery instance.

Parameters

  • $chances int|float
  • $outOf int|null
public

winner ( $callback ) : $this

Set the winner callback.

Parameters

  • $callback callable
public

loser ( $callback ) : $this

Set the loser callback.

Parameters

  • $callback callable
public

__invoke ( $args ) : mixed

Run the lottery.

Parameters

  • $args mixed
public

choose ( $times ) : mixed

Run the lottery.

Parameters

  • $times null|int
protected

runCallback ( $args ) : callable

Run the winner or loser callback, randomly.

Parameters

  • $args mixed
protected

wins ( ) : bool

Determine if the lottery "wins" or "loses".

protected static

resultFactory ( ) : callable

The factory that determines the lottery result.

public static

alwaysWin ( $callback ) : void

Force the lottery to always result in a win.

Parameters

  • $callback callable|null
public static

alwaysLose ( $callback ) : void

Force the lottery to always result in a lose.

Parameters

  • $callback callable|null
public static

fix ( $sequence , $whenMissing ) : void

Set the sequence that will be used to determine lottery results.

Parameters

  • $sequence array
  • $whenMissing callable|null
public static

forceResultWithSequence ( $sequence , $whenMissing ) : void

Set the sequence that will be used to determine lottery results.

Parameters

  • $sequence array
  • $whenMissing callable|null
public static

determineResultNormally ( ) : void

Indicate that the lottery results should be determined normally.

public static

setResultFactory ( $factory ) : void

Set the factory that should be used to determine the lottery results.

Parameters

  • $factory callable