5 months ago

Getting extra data from pivot table

Posted 5 months ago by SarahS74

I have an Users table and a Books table. I also have a Book_User pivot table with 3 extra columns (own|read|wishlist).

I'm trying to show on my Author page a list of Books the author has and then via Buttons which ones I have read/owned/wishlist.

            @foreach ($author->books->sortByDesc('year') as $book)
                    <a href="/books/{{ $book->id }}">{{ $book->title }}-<em>{{ $book->series->name }} Series</em> ({{ $book->year }})</a>
                    <form action="{{ $author->path() . '/books/'.$book->id }}" method="POST">
                        <button class="btn btn-sm {{  $book->pivot->own === "1" ? "btn-primary" : "btn-secondary" }}" name="read" value="1">Read It</button>
                        <button class="btn btn-sm btn-primary" name="own" value="1">Own It</button>
                        <button class="btn btn-sm btn-primary" name="wish" value="1">Wishlist</button>

I can't seem to get the data from the pivot table though to work. This line here:


doesn't do it. Where am I going wrong?

Please sign in or create an account to participate in this conversation.