Flex

how to create table relationship in Laravel

Posted 1 year ago by Flex

hello, I am developing project management application using laravel 5.2 and in my app user can create projects and each project have many tasks and each task have many sub tasks as well. in my table project and task table have following relationship. task model relationship with project model is

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

project model relationship with task table

 public function tasks(){
         return $this->hasMany('App\Task');
}

now My subtask table as following

id    subtask  task_id   project_id
1          abc          2              1
2          dfg          2              1
3          frt            3              2

how can I create subtasks model in relationship with project and task table?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.