Я не знаю, как можно решить эту проблему, мне нужно посчитать книги по домену. Пример:
domaine #Science (10 книг)
Вот мой код:
<tbody>
<?php $book = Book::orderBy('id', 'desc')->get(); ?>
@if(count($book) >= 1)
@foreach($domaines as $domaine)
<tr class="tr-body">
<td>{{ $domaine->name }}</td>
<td>
({{ $domaine->book->count() }})
</td>
<td>
<a href="{{ URL::current() . '?id=' . $domaine->id }}" class="btn btn-success btn-sm"><i class="fa fa-edit large"></i></a>
<a onclick="return confirm('{{ Lang::get($path.'.delete') }}')" href="{{ URL::route('domaine_delete', $domaine->id) }}" class="btn btn-danger btn-sm">
<i class="fas fa-trash"></i></a>
</td>
</tr>
@endforeach
@endif
</tbody>
МОДЕЛЬ:
Domaine model : <?php class Domaine extends Eloquent { protected $guarded = ['id', 'created_at']; protected $table = 'domaines'; public function books() { return $this->hasMany('book'); } }
Book model : <?php class Book extends Eloquent { protected $guarded = ['id', 'created_at']; protected $table = 'books'; }
* * 1016