phpmysqllaravelcrudlaravel-8

Laravel 8 - Could not find driver : Illuminate\Database\QueryException could not find driver (SQL: select * from `list`)


I have installed Laravel 8 on my Linux Mint 20 for my personal experiment so I'm new on Laravel's new version. I've searching many source how to show tables with CRUD method so the table is shown in the web with contains data from MySQL database

But when i tried to show table with CRUD method, it appeared like this :

Illuminate\Database\QueryException could not find driver (SQL: select * from list)

in localhost:8000/home/tabel

I tried to solving this problem from repairing .env file, Controller file, blade file, and the web.php to be correct but it still error.

And this is my configuration file which i've change like this :

.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>

and then 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

For MySQL database i use XAMPP

Can anyone explain why this is error and give me solution what should I do to repair this?


Solution

  • Just install appropriate driver for PHP-MySQL:

    # default
    sudo apt install php-mysql
    # for specific version of php (e.g. php7.4)
    sudo apt install php7.4-mysql
    

    Restart your server:

    # apache
    sudo systemctl restart apache2
    # nginx
    sudo systemctl restart nginx