1

The following query works fine, but the problem is that it gives the id of the events table instead of tasks table id in the output result.

Task::join('events', function ($join) {
    $join->on('events.task_id', '=', 'tasks.id')
        ->where('events.event_type', '=', 'Task')
        ->where('events.task_stage', '!=', 'assigned');
})->select('tasks.*')
->get();
1
  • this one duplicate Commented Jun 18, 2019 at 6:04

2 Answers 2

2

Try this, one should work

->select('*', 'tasks.id as taskID')->get();

This is because maybe both tasks and events table have id field. So u need to use a separate query to specify the id.

Sign up to request clarification or add additional context in comments.

Comments

2

try this one

use mysql alias here

Task::join('events', function ($join) {
        $join->on('events.task_id', '=', 'tasks.id')
            ->where('events.event_type', '=', 'Task')
            ->where('events.task_stage', '!=', 'assigned');
 })->select('tasks.*','tasks.id as taskId')->get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.