@@ -13,7 +13,7 @@ use App\Models\Author;
class BookController extends Controller {
function index() {
- $books = Book::all(); // Достать все книги
+ $books = Book::all()->load("author"); // Достать все книги
return view("books", ["rows" => $books]);
}
@@ -9,6 +9,7 @@
<th>ISBN</th>
<th>Год</th>
<th>Страниц</th>
+ <th>Автор</th>
</tr>
@foreach ($rows as $row)
<tr>
@@ -17,6 +18,7 @@
<td>{{$row->isbn}}</td>
<td>{{$row->year}}</td>
<td>{{$row->pagecount}}</td>
+ <td><a href="/author/{{$row->author->id}}">{{$row->author->name}}</a></td>
@endforeach
</table>