sustained's avatar

Query works fine via php artisan tinker but not in browser?

Basically what it says in the title.

Input (command line)

>>> \App\Project::all();

Output

=> Illuminate\Database\Eloquent\Collection {#2911
     all: [
       App\Project {#2912
         id: "1",
         title: "A Project",
         description: "Best project ever.",
         created_at: "2018-11-13 03:29:55",
         updated_at: "2018-11-13 03:29:55",
       },
     ],
   }

Code (browser)

    public function index()
    {
        $projects = \App\Project::all();

        return view('projects.index');
    }

Error

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

I have verified that the PHP versions/INI configuration files are the same (Google said that multiple installations of PHP could be the cause).

Extra Info.

        PHP Version => 7.1.23
        System => Linux Fedora x86_64
        PDO support => enabled
        PDO drivers => pgsql, sqlite
        PDO Driver for SQLite 3.x => enabled
        SQLite Library => 3.20.1
        SQLite3 support => enabled
        SQLite3 module version => 7.1.23
0 likes
2 replies
mattsplat's avatar
Level 8

Try running php artisan config:cache it looks like its not reading your .env

1 like
sustained's avatar

Yeah, already got it but thanks! This isn't the first time this has caught me out.

I already eventually ended up trying php artisan config:cache and it didn't work!

But then after a bit more headscratching I restarted the dev server and it did indeed work.

Please or to participate in this conversation.