how to make 7 join into eloquent query hello all ,
I have this query
SELECT scenarios.name, scenarios.id, applications.name FROM users INNER JOIN tokens_assign ON tokens_assign.user_id = users.id INNER JOIN tokens ON tokens_assign.token_id = tokens.id INNER JOIN application_tokens ON application_tokens.token_id = tokens.id INNER JOIN applications ON applications.id = application_tokens.app_id INNER JOIN scenario_teams ON scenario_teams.team_id = tokens.team_id INNER JOIN scenarios ON scenarios.id = scenario_teams.scenario_id INNER JOIN application_scenarios ON application_scenarios.scenario_id = scenarios.id AND application_scenarios.app_id = applications.id where scenario_teams.team_id=34 ORDER BY scenarios.id
how Is possible to be convert with eloquent? i mean by WITH
Ill get you started and you can do the rest
DB::table('users')
->select(['scenarios.name', 'scenarios.id', 'applications.name'])
->join('tokens', 'tokens_assign.token_id', 'tokens.id')
->join('applications', 'application_tokens.app_id', 'applications.id')
...etc
->where('scenario_teams.team_id', 34)
->orderBy('scenarios.id')
->get();
@Sinnbeck correct :) but there is any way By WITH ?
@coustas with is not joins. It does a query for every with() you add
@Sinnbeck Is it possible to write two conditions in the join clause ?
INNER JOIN application_scenarios ON application_scenarios.scenario_id = scenarios.id AND application_scenarios.app_id = applications.id
@coustas
Would something like this help you?
$sql = /* very complex SQL query, using hard to replicate in builder features (WITH, LATERAL, etc.) */;
$bindings = [/* query parameters to be escaped */];
$models = Model::query()->fromQuery($sql, $bindings);
Please sign in or create an account to participate in this conversation.