MovieZ
MovieZ

Reputation: 409

What relationship do I need?

I have Folder model, and the problem is, that I want to have Folder inside another Folder, what relationship can I use in this situation? I thought of adding one more column to Folder model, something like "parentFolderId", is it correct solution in this situation?

Upvotes: 1

Views: 37

Answers (1)

Dilip Hirapara
Dilip Hirapara

Reputation: 15296

Table folder

* id 
* name
* parent_folder_id

Now in the folder model, you can make a hasMany Relation. cause one folder has many folders.

function folders(){
    return $this->hasMany('App\Folder','parent_folder_id','id');
}

Upvotes: 4

Related Questions