Title
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_id' in 'where clause' (SQL: select * from
outcomeswhere (user_id= 37 and todos.outcome_id = outcomes.id) andoutcomes.deleted_atis null)
In my laravel project I want to get the list of all task there corresponding Outcome values but this gives an error
public function kanban()
{
$outcomes = Outcome::with('todos')
->where(function ($query) {
$query->select(DB::raw(1))
->from('todos')
->where('user_id','=',Auth::user()->id)
->whereRaw('todos.outcome_id = outcomes.id');
})
->get();
return view('taskmanagement.cruds.user.kanban',compact('outcomes'));
}
Here My Todo model
<?php
namespace App;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Todo extends Model
{
use SoftDeletes;
//Table Name
protected $table = 'todos';
//Primary key
public $primaryKey = 'id';
protected $fillable = [
'todoable_id',
'todoable_type',
'title',
'description',
'admin_id',
'user_id',
'project_id',
'priority',
'outcome_id',
'tasktype_id',
'started_at',
'due_time',
'completed_at',
];
public function outcome() {
return $this->belongsTo('App\Outcome');
}
public function user() {
return $this->belongsTo('App\User');
}
public function todoable()
{
return $this->morphTo();
}
}
Outcome Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Outcome extends Model
{
use SoftDeletes;
//Table Name
protected $table = 'outcomes';
//Primary key
public $primaryKey = 'id';
protected $fillable = [
'name'
];
public function todos() {
return $this->hasMany('App\Todo');
}
}
