Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descendants Relationship doesn't work #557

Open
ComputerMaverick69 opened this issue May 5, 2022 · 3 comments
Open

Descendants Relationship doesn't work #557

ComputerMaverick69 opened this issue May 5, 2022 · 3 comments

Comments

@ComputerMaverick69
Copy link

I have created a $node like $node = new Category(); and have saved the category. I then use the parent's children relationship to create a child node like this $parent->children()->create($attributes); This gets properly saved in the database but when i use the descendants relationship it shows an empty array but in the database, it shows the parent_id column as having a parent.

$categories = Category::with('descendants')->select([
            'title',
            'subtitle',
            'img',
            'status'
        ])->whereNull('parent_id')->get();

//In blade I do
@foreach ($categories as $i => $subCategory)
      <tr>
          <td>{{ $subCategory->descendants->pluck('title') }}</td>
          <td>{{ $subCategory->descendants->pluck('subtitle') ?? 'N/A' }}</td>
          <td>{{ $subCategory->title ?? 'N/A' }}</td>
          <td>@if($subCategory->descendants->pluck('img') == null) N/A @else <img src="{{ $subCategory->descendants->pluck('img') }}" width="30" />  @endif</td>
          <td>{{ ucfirst($subCategory->descendants->pluck('status')) }}</td>
          <td>
              <a href="{{ route('sub-categories.edit', $subCategory->descendants->pluck('id')) }}" class="btn btn-sm btn-info btn-b">
                  <i class="las la-pen"></i>
              </a>
              <form action="{{ route('sub-categories.destroy', $subCategory->descendants->pluck('id')) }}" method="post">
                  @csrf
                  @method('DELETE')
                  <button type="submit" class="btn btn-sm btn-danger"><i class="las la-trash"></i></button>
              </form>
          </td>
      </tr>
@endforeach

It comes off a a blank array []

Screenshot 2022-05-05 at 11 18 41 AM

Screenshot 2022-05-05 at 11 19 40 AM

@fadedhero
Copy link

fadedhero commented May 12, 2022

I can reproduce this by updating mysql from 8.0.28 to 8.0.29.
Are you using mysql?

@ComputerMaverick69
Copy link
Author

Yes i am

I can reproduce this by updating mysql from 8.0.28 to 8.0.29. Are you using mysql?

@fadedhero
Copy link

Changing from a View to a Table solved my issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants