Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

349
Views
Laravel display related users via orgchart.js

I am new to laravel and i barely managed to do up until this point.

I need guidance on putting the data @dump on the organigram.

I really have no idea where to start this. Any direction or idea is appreciated.

There are users who are referred by others, and the actual result shows the hierarchy of the user, who is referred by who. For instance, you can see that user with id 27 has referred 3 other user under him, 35,36, 38, and 36 has referred an additional user with ID 37.

thank you

User Controller

public function viewRelated()
{
    $roles = collect(Role::whereIn('slug', array_merge(Role::FIRST_PARTY_ROLES, Role::SECOND_PARTY_ROLES, ['master']))->get())->keyBy('id')->toArray();
    $users = User::whereIn('role', array_keys($roles))
                ->where('email_verified_at', '<>', null)
                ->where('account_verified_at', '<>', null)->get();

    $users = $this->buildUserHierarchy($users);
    
    return view('dashboard.admin.users.relationships', ['users' => $users]);
}

protected function buildUserHierarchy($users, $user_id = null, $level = 0)
{
    $users_tree = [];
    $parents = collect($users)->where("assigned_to", "==", $user_id)->values();

    foreach ($parents as $child) {
        $child->users = $this->buildUserHierarchy($users, $child->id, $level + 1);
        $item = [
            'id' => $child->id,
            'name' => $child->name . ' ' . $child->surname,
            'email' => $child->email,
            'role' => Role::find($child->role)->name,
            'users' => $this->buildUserHierarchy($users, $child->id, $level + 1),
        ];

        $users_tree[$child->id] =  $item;
    }
    return $users_tree;
}

Route for Admin

   Route::get('list', 'App\Http\Controllers\Dashboard\UserController@viewRelated')->name('user.list');

Blade

<div class="row">
  <div> 
    @if($users)
        @dump($users)
    @endif  

  </div>
</div>

Actual Result

Actual Results

Desired Result using OrgChart Js

enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!