我已经在我的 Linux Mint 20 上安装了 Laravel 8 作为我的个人实验,所以我对 Laravel 的新版本很陌生。我搜索了许多来源如何使用 CRUD 方法显示表,以便该表显示在网络中,其中包含来自 MySQL 数据库的数据
但是当我尝试用 CRUD 方法显示表时,它看起来像这样:
照亮\数据库\QueryException
找不到驱动程序(SQL:select * fromlist
)
在本地主机:8000/home/tabel
我尝试通过修复 .env 文件、控制器文件、blade 文件和 web.php 来解决此问题,使其正确,但仍然错误。
这是我的配置文件,我对其进行了如下更改:
.env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=people
DB_USERNAME=root
DB_PASSWORD=
homeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class homeController extends Controller
{
public function home()
{
return "home";
}
public function tabel()
{
$tabelku = DB::table('list')->get();
return view('tabel', ['people' => $tabelku]);
}
}
tabel.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Table</title>
</head>
<body>
<div align="center">
<table border = "1">
<tr>
<th>No</th>
<th>Name</th>
<th>Age</th>
<th>Hobby</th>
</tr>
@foreach($tabelku as $t)
<tr>
<th>{{$t->no}}</th>
<th>{{$t->name}}</th>
<th>{{$t->age}}</th>
<th>{{$t->hobby}}</th>
</tr>
@endforeach
</table>
</div>
</body>
</html>
然后是 web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/hello', function () {
return 'Halo Dunia';
});
Route::get('/home','homeController@home');
Route::get('/home/tabel','homeController@tabel');
And this is database and table which i use to show tables from CRUD method -> ![enter image description here](https://i.stack.imgur.com/B0iPn.png)
对于 MySQL 数据库,我使用 XAMPP
谁能解释为什么这是错误并给我解决方案我应该做什么来修复这个问题?