Laravel Eloquent crossJoin() Query Example

Admin   Laravel   334  2021-03-15 19:40:07

Hello Friend,

In this blog, I would like to share with you laravel crossjoin query example. We will show crossjoin query in laravel.

To perform a "cross join" use the crossJoin method with the name of the table you wish to cross join to. Cross joins generate a cartesian product between the first table and the joined table.

Here, i will give you demo for example crossjoin with output i think you see demo after that you will understood it. So Let's see demo and output for crossjoin query in laravel application.

In the example, I will give you demo and example for crossjoin query in laravel. So let's see bellow demo and example.



$colors = collect(['white','black']);

$sizes = ['1','2'];

$data = $colors->crossJoin($sizes);


You can see bellow output to understood crossjoin query in laravel. and next in example for crossjoin query builder laravel:

Output :

Example : 1


$employees = DB::table('employees')



Example : 2


$employees = Employee::crossJoin('departments')->get();

It will help yoiu...