i am try to display nested list using Laravel.
class Person extends Model
{
public function father()
{
return $this->belongsTo('App\Person', 'father_id');
}
}
I can access Data manually like bellow.
user = \App\Person::find(5);
$this->tree_string .= "<li>";
$this->tree_string .= "<label>".$user->name."</label>";
$user = $user->father;
$this->tree_string .= "<ul><li>";
$this->tree_string .= "<label>".$user->name."</label>";
$user = $user->father;
$this->tree_string .= "<ul><li>";
$this->tree_string .= "<label>".$user->name."</label>";
$this->tree_string .= "</li></ul>";
$this->tree_string .= "</li></ul>";
$this->tree_string .= "</li>";
but how do i do this in loop until there is no father.(like foreach) is the method i am using correct.