master

laravel/framework

Last updated at: 29/12/2023 09:22

CrossJoinSequence.php

TLDR

The CrossJoinSequence class in the Illuminate\Database\Eloquent\Factories namespace is used to create a new cross join sequence instance.

Classes

CrossJoinSequence

The CrossJoinSequence class extends the Sequence class and is used to create a new cross join sequence instance. It takes an arbitrary number of arrays as parameters and cross joins them together using the crossJoin method from the Arr class. The resulting cross joined arrays are then merged using the array_merge function. The cross join sequence is passed to the parent Sequence class constructor.

<?php

namespace Illuminate\Database\Eloquent\Factories;

use Illuminate\Support\Arr;

class CrossJoinSequence extends Sequence
{
    /**
     * Create a new cross join sequence instance.
     *
     * @param  array  ...$sequences
     * @return void
     */
    public function __construct(...$sequences)
    {
        $crossJoined = array_map(
            function ($a) {
                return array_merge(...$a);
            },
            Arr::crossJoin(...$sequences),
        );

        parent::__construct(...$crossJoined);
    }
}