目前,我的数据库中有这2个不同的。views
第一个是列出所有项目及其详细信息的地方view_project_percentage
以及每个特定项目的任务列表view_projtask
view_project_percentage
view_projtask
我有这个工作代码
我的模型
Project.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = "view_project_percentage";
public function tasks()
{
return $this->hasMany(ProjectTask::class, 'projCode', 'proj_code')
->where('deleted',0);
}
}
和
ProjectTask.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectTask extends Model
{
protected $table = "view_projtask";
public function project()
{
return $this->belongsTo(Project::class, 'proj_code', 'projCode')
->where('deleted',0)
->where('taskDeleted',0);
}
}
在我的我有这个Controller
public function get_all_projtask()
{
return response()->json(Project::with('tasks')->get());
}
猛跑小猪