【发布时间】:2023-03-13 14:14:01
【问题描述】:
您好,我刚开始在 laravel 8 中工作,我想知道如何在数据库中获取数据并打印数据
我有一个带有搜索栏的表格模板,可以在我们的数据库中查看和查找用户
这是我们的表格控制器
仪表板控制器
<?php
namespace App\Http\Controllers;
use Auth;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function dashboard()
{
$dashboardTitle = "Dashboard";
$isCurrent = "dashboard";
return view('dashboard.index', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function profile()
{
$dashboardTitle = "Profile";
$isCurrent = "Profile";
return view('dashboard.profile', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function directory()
{
$dashboardTitle = "Directory";
$isCurrent = "Directory";
return view('dashboard.directory', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function journal()
{
$dashboardTitle = "Journal";
$isCurrent = "Journal";
return view('dashboard.journal', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
public function files()
{
$dashboardTitle = "Files";
$isCurrent = "Files";
return view('dashboard.files', [
'dashboardTitle' => $dashboardTitle,
'isCurrent' => $isCurrent
]
);
}
}
这里是风景
目录
@extends('dashboard.layouts.dashboard-layout')
@push('css')
<!-- Custom styles for this page -->
<link href="{{asset('dashboards/vendor/datatables/dataTables.bootstrap4.min.css')}}" rel="stylesheet">
@endpush
@section('content')
<!-- Page Heading -->
<h1 class="h3 mb-2 text-gray-800">Tables</h1>
<p class="mb-4">DataTables is a third party plugin that is used to generate the demo table below.
For more information about DataTables, please visit the <a target="_blank"
href="https://datatables.net">official DataTables documentation</a>.</p>
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">DataTables Example</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<td></td>
<td></td>
<td></td>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
</div>
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
@endsection
@push('script')
<!-- Page level plugins -->
<script src="{{asset('dashboards/vendor/datatables/jquery.dataTables.min.js')}}"></script>
<script src="{{asset('dashboards/vendor/datatables/dataTables.bootstrap4.min.js')}}"></script>
<!-- Page level custom scripts -->
<script src="{{asset('dashboards/js/demo/datatables-demo.js')}}"></script>
@endpush
我们的表名是 users,我想使用循环将其打印在表中
【问题讨论】:
标签: php mysql laravel loops fetch