Php 如何在Laravel 5.2中显示有关id的表格数据

Php 如何在Laravel 5.2中显示有关id的表格数据,php,laravel-5,Php,Laravel 5,我正在使用Laravel开发项目管理应用程序。在我的应用程序中,我有一个项目,一个项目有许多任务,一个任务有许多注释 因此,我有注释表,如下所示 id comment project_id user_id 1 abc 1 1 2 dcf 1 2 3 fgt

我正在使用Laravel开发项目管理应用程序。在我的应用程序中,我有一个项目,一个项目有许多任务,一个任务有许多注释

因此,我有注释表,如下所示

id    comment            project_id            user_id
1         abc               1                    1
2        dcf                1                    2
3        fgt                2                    1
4        fgt                2                    2
5        fhgt               1                    3
public function postNewComment(Request $request, $id, Comment $comment)
{
    $this->validate($request, [
        'comments' => 'required|min:5',
    ]);

    $comment->comments   = $request->input('comments');
    $comment->project_id = $id;
    $comment->user_id    = Auth::user()->id;
    $comment->save();

    return redirect()->back()->with('info', 'Comment posted successfully');
}
class Comment extends Model
{

    protected $fillable = ['comments', 'project_id', 'user_id'];

        public function scopeProject($query, $id)
    {
        return $query->where('project_id', $id);
    }



     public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function project()
    {
        return $this->belongsTo('App\Project');
    }

}
评论控制器评论帖子如下

id    comment            project_id            user_id
1         abc               1                    1
2        dcf                1                    2
3        fgt                2                    1
4        fgt                2                    2
5        fhgt               1                    3
public function postNewComment(Request $request, $id, Comment $comment)
{
    $this->validate($request, [
        'comments' => 'required|min:5',
    ]);

    $comment->comments   = $request->input('comments');
    $comment->project_id = $id;
    $comment->user_id    = Auth::user()->id;
    $comment->save();

    return redirect()->back()->with('info', 'Comment posted successfully');
}
class Comment extends Model
{

    protected $fillable = ['comments', 'project_id', 'user_id'];

        public function scopeProject($query, $id)
    {
        return $query->where('project_id', $id);
    }



     public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function project()
    {
        return $this->belongsTo('App\Project');
    }

}
这是我的评论模型如下所示

id    comment            project_id            user_id
1         abc               1                    1
2        dcf                1                    2
3        fgt                2                    1
4        fgt                2                    2
5        fhgt               1                    3
public function postNewComment(Request $request, $id, Comment $comment)
{
    $this->validate($request, [
        'comments' => 'required|min:5',
    ]);

    $comment->comments   = $request->input('comments');
    $comment->project_id = $id;
    $comment->user_id    = Auth::user()->id;
    $comment->save();

    return redirect()->back()->with('info', 'Comment posted successfully');
}
class Comment extends Model
{

    protected $fillable = ['comments', 'project_id', 'user_id'];

        public function scopeProject($query, $id)
    {
        return $query->where('project_id', $id);
    }



     public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function project()
    {
        return $this->belongsTo('App\Project');
    }

}
在我的应用程序中,用户可以使用
projectController
index
功能访问他们的项目区域

public function index()
     {
        $projects = Project::all();
        return view('projects.index')->withProjects($projects);
}
然后,当点击一个项目链接时,用户可以看到创建的任务表单和相关项目的现有任务列表。“我的任务创建表单”位于“资源”文件夹中“视图文件”的“项目”文件夹中,现有任务列表包含在此文件中
projects/show.blade.php

 @include('tasks.index')
tasks/index.blade.php
文件是

@foreach ($project->tasks as $task)
    <h4><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a></h4>
@endforeach
现在,当我点击一个现有的任务链接时,我可以看到注释框,现在我需要显示与每个项目相关的每个任务的注释表注释。我是说我需要 显示每个项目对与该项目相关的每个任务的评论

你能给我一些帮助吗

谢谢