Answer the question
In order to leave comments, you need to log in
Why is laravel trying to access a column from another table?
When displaying the table, an error is displayed:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'office_to_do_projects.project_id' in 'where clause' (SQL: select * from `office_to_do_projects` where `office_to_do_projects`.`project_id`=1 and `office_to_do_projects`.`project_id` is not null and `office_to_do_projects`.`deleted_at` is null) (View: C:\OSPanel\domains\vs.develop\resources\views\page\Office\ToDo\Projects.blade.php)
SQLSTATE [42S22]: Column not found: 1054 Unknown column 'office_to_do_projects.project_id' in 'where' clause (SQL: select * from `office_to_do_projects` where `office_to_do_projects``project_id` = 1 and `office_to_do_projects``project_id` equals not is NULL and `office_to_do_projects` .deleted_at` is nil)
@foreach($projects as $project)
***
<td>{{ count($project->tasks()->get()) }}</td>
***
$user = Auth::user();
$projects = Auth::user()->toDoProjects()->orderby('created_at')->get();
$currenttime = Carbon::now()->format('h:i a');
$today = Carbon::now()->formatLocalized('%a %d %b %y');
return view('page.Office.ToDo.Projects', compact('projects', 'currenttime', 'today', 'user'));
public function toDoProjects(){
return $this->hasMany('App\Models\Office\ToDo\Project');
}
public function toDoTasks(){
return $this->hasManyThrough('App\Models\Office\ToDo\Task', 'App\Models\Office\ToDo\Project');
}
use SoftDeletes;
protected $table = 'office_to_do_projects';
protected $dates = ['deleted_at'];
protected $fillable = [
'name',
'slug',
'desc',
'duedate',
'completed'
];
public function setDuedateAttribute($date){
$this->attributes['duedate'] = Carbon::parse($date);
}
public function user(){
return $this->belongsTo('App\User');
}
public function tasks(){
return $this->hasMany('App\Models\Office\ToDo\Task');
}
public function subtasks(){
return $this->hasManyThrough('App\Models\Office\ToDo\Subtask', 'App\Models\Office\ToDo\Task');
}
use SoftDeletes;
protected $table = 'office_to_do_projects';
protected $dates = ['deleted_at'];
protected $fillable = [
'name',
'slug',
'desc',
'duedate',
'completed'
];
public function setDuedateAttribute($date){
$this->attributes['duedate'] = Carbon::parse($date);
}
public function user(){
return $this->belongsTo('App\User');
}
public function project(){
return $this->belongsTo('App\Models\Office\ToDo\Project');
}
public function subtasks(){
return $this->hasMany('App\Models\Office\ToDo\Subtask');
}
$table->bigIncrements('id');
$table->bigInteger('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('name');
$table->string('slug');
$table->longText('desc');
$table->date('duedate');
$table->boolean('completed')->default(false);
$table->timestamps();
$table->softDeletes();
$table->bigIncrements('id');
$table->bigInteger('project_id')->unsigned()->index();
$table->foreign('project_id')->references('id')->on('office_to_do_projects')->onDelete('cascade');
$table->string('name');
$table->string('slug');
$table->longText('desc');
$table->date('duedate');
$table->boolean('completed')->default(false);
$table->timestamps();
$table->softDeletes();
$table->bigIncrements('id');
$table->bigInteger('task_id')->unsigned()->index();
$table->foreign('task_id')->references('id')->on('office_to_do_tasks')->onDelete('cascade');
$table->string('name');
$table->string('slug');
$table->longText('desc');
$table->date('duedate');
$table->boolean('completed')->default(false);
$table->timestamps();
$table->softDeletes();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question