On this page
Lottery
class Lottery (View source)
Properties
protected int|float | $chances | The number of expected wins. |
|
protected int|null | $outOf | The number of potential opportunities to win. |
|
protected null|callable | $winner | The winning callback. |
|
protected null|callable | $loser | The losing callback. |
|
static protected callable|null | $resultFactory | The factory that should be used to generate results. |
Methods
void | __construct(int|float $chances, int|null $outOf = null) Create a new Lottery instance. |
|
static Lottery | odds(int|float $chances, int|null $outOf = null) Create a new Lottery instance. |
|
$this | winner(callable $callback) Set the winner callback. |
|
$this | loser(callable $callback) Set the loser callback. |
|
mixed | __invoke(mixed ...$args) Run the lottery. |
|
mixed | choose(null|int $times = null) Run the lottery. |
|
callable | runCallback(mixed ...$args) Run the winner or loser callback, randomly. |
|
bool | wins() Determine if the lottery "wins" or "loses". |
|
static callable | resultFactory() The factory that determines the lottery result. |
|
static void | alwaysWin(callable|null $callback = null) Force the lottery to always result in a win. |
|
static void | alwaysLose(callable|null $callback = null) Force the lottery to always result in a lose. |
|
static void | fix(array $sequence, callable|null $whenMissing = null) Set the sequence that will be used to determine lottery results. |
|
static void | forceResultWithSequence(array $sequence, callable|null $whenMissing = null) Set the sequence that will be used to determine lottery results. |
|
static void | determineResultNormally() Indicate that the lottery results should be determined normally. |
|
static void | setResultFactory(callable $factory) Set the factory that should be used to determine the lottery results. |
Details
void __construct(int|float $chances, int|null $outOf = null)
Create a new Lottery instance.
static Lottery odds(int|float $chances, int|null $outOf = null)
Create a new Lottery instance.
$this winner(callable $callback)
Set the winner callback.
$this loser(callable $callback)
Set the loser callback.
mixed __invoke(mixed ...$args)
Run the lottery.
mixed choose(null|int $times = null)
Run the lottery.
protected callable runCallback(mixed ...$args)
Run the winner or loser callback, randomly.
protected bool wins()
Determine if the lottery "wins" or "loses".
static protected callable resultFactory()
The factory that determines the lottery result.
static void alwaysWin(callable|null $callback = null)
Force the lottery to always result in a win.
static void alwaysLose(callable|null $callback = null)
Force the lottery to always result in a lose.
static void fix(array $sequence, callable|null $whenMissing = null)
Set the sequence that will be used to determine lottery results.
static void forceResultWithSequence(array $sequence, callable|null $whenMissing = null)
Set the sequence that will be used to determine lottery results.
static void determineResultNormally()
Indicate that the lottery results should be determined normally.
static void setResultFactory(callable $factory)
Set the factory that should be used to determine the lottery results.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/10.x/Illuminate/Support/Lottery.html