I'm working with a Laravel 5.5 project .
I have locations
table with the following definition:
$table->increments('id');
$table->string('location_name',50);
$table->integer('location_id')->unsigned();
$table->foreign('location_id')->references('id')->on('locations');
$table->softDeletes();
$table->timestamps();
now the primary key and the forgen key at same table id and location id and id have this relation in location model
public function get_sub()
{
return $this->hasMany('App\Location','location_id','id');
}
public function get_father()
{
return $this->belongsTo('App\Location','location_id','id');
}
now i need to draw ul li tree view to start with location_id is null i did this
@foreach($locations->where('location_id','=','null') as $location)
@endforeach
this loop start the first parent location
what i am need is while loop or for loop to nest all children locations inside the first foreach loop and nest the grandchildren inside the children loop as ul li or anything else like this photo
thanks