我想在表格中显示所有数据,表格名为taglineImageCarousel,问题出在slide_ID上,它填满了幻灯片01,幻灯片02和幻灯片03的数据
这里是代码
taglineImageCarouselController.php
<?php
namespace AppHttpControllers;
use AppModelstaglineImageCarousel;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;
class taglineImageCarouselController extends Controller
{
// Controller untuk menampilkan data tabel taglineImageCarousel di dashboard
// landing page
function index()
{
$taglineImage = DB::table('taglineImageCarousel')->get();
return view('pages.landingpage.landingpage', ['taglineImage' => $taglineImage]);
}
}
然后将路由代码放入web.php文件
use AppHttpControllerstaglineImageCarouselController;
Route::get('/landingpage', [taglineImageCarouselController::class, 'index']);
我已经创建了模型文件taglineimagecarousel。php
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class taglineImageCarousel extends Model
{
use HasFactory;
}
最后,我尝试在我的landingpage.blade.php中显示数据,它位于views/pages/landingpage/landingpage.blade.php
文件中<?php
foreach ($taglineImage as $tagline)
{
$id = $tagline->slide_ID;
$status = $tagline->status;
}
?>
<tbody> <!--Isi Tabel -->
@foreach($taglineImage as $tagline)
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $status; ?></td>
<td><a href=Home.html>detail</a></td>
</tr>
@endforeach
</tbody>
当我运行它,它会显示一个表,只有充满了slide-03数据(这是第三个数据在我的表)。有人知道怎么解决这个问题吗?
好了,看来多亏了brombeer的建议,我只需要重写我的landing - blade.php代码到
<tbody>
@foreach($taglineImage as $tagline)
<tr>
<td>{{$tagline->slide_ID}}</td>
<td>{{$tagline->status}}</td>
<td><a href=Home.html>detail</a></td>
</tr>
@endforeach
</tbody>