我正在使用文件上传创建一个简单的crud应用程序。但我在视图中显示缩略图时遇到问题(index.blade.php)。数据库中的所有图像都显示在每本书中,而不是在一本书中显示一个图像。这是我的控制器。
public function index()
{
$books=UploadedFile::all();
$files=Upload::all();
return view('books.index',compact('books','files'));
}

和我的index.blade.php
<table class="table table-striped table-bordered table-hover">
<thead>
<tr class="bg-info">
<th>Id</th>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Thumbs</th>
<th colspan="3">Actions</th>
</tr>
</thead>
<tbody>
@foreach ($books as $book )
<tr>
<td>{{ $book->id }}</td>
<td>{{ $book->isbn }}</td>
<td>{{ $book->title }}</td>
<td>{{ $book->author }}</td>
<td>{{ $book->publisher }}</td>
<td>
@foreach ($files as $file )
<img src="{{asset('uploads/'.$file->filename)}}" height="40" width="50">
@endforeach
</td>
<td><a href="{{url('books',$book->id)}}" class="btn btn-primary">Details</a></td>
<td><a href="{{route('books.edit',$book->id)}}" class="btn btn-warning">Update</a></td>
<td>
{!! Form::open(['method' => 'DELETE', 'route'=>['books.destroy', $book->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
&#13;
我将表格与其他字段分开。这是结果 -