【发布时间】:2021-06-10 11:49:24
【问题描述】:
我已经在我的 Linux Mint 20 上安装了 Laravel 8 用于我的个人实验,所以我是 Laravel 新版本的新手。我已经搜索了许多来源如何使用 CRUD 方法显示表格,以便表格显示在 Web 中,其中包含来自 MySQL 数据库的数据
但是当我尝试使用 CRUD 方法显示表格时,它看起来像这样:
照亮\数据库\查询异常 找不到驱动程序 (SQL: select * from
list)
在 localhost:8000/home/tabel
我试图通过修复.env文件、控制器文件、刀片文件和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');
对于 MySQL 数据库,我使用 XAMPP
谁能解释为什么这是错误并给我解决方案我应该怎么做才能修复它?
【问题讨论】:
-
"could not find driver" 表示 PHP 找不到 mysql / pdo_mysql 扩展。您必须在
php.ini中启用它
标签: php mysql laravel crud laravel-8