skip to Main Content

i was learning laravel6 from scratch from laracast.com and when i started to use the database. I bumped into the following problem:

IlluminateDatabaseQueryException could not find driver (SQL: select
* from posts where slug = my-first-post limit 1)

I use wamp with phpmyadmin. I tried xamp and mySQL workbench. I updated my dependencies, but without result.

this is my controller:

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class PostsController extends Controller
{
    public function show($slug)
    {
        $post = DB::table('posts')->where('slug', $slug)->first();

        if(! $post){
            abort(404);
        }

     return view('post', [
         'post' => $post
     ]);
    }
}

Can somebody please help me with this problem?

Best regards,
Jeff

2

Answers


  1. Chosen as BEST ANSWER

    When i installed composer. I needed to assign the location of my php.exe. This field was empty so i installed php when i already had wampp installed.

    Solution: I uninstalled wampp, composer and deleted php. I started over and installed xampp first. When i wanted to install composer. It immediately suggested php.exe in my xampp folder. After installing laravel the problem was solved.

    Conclusion: Composer installation went wrong. Since i had multiple php's in my system i probably assignt composer to the wrong one.

    Thanks for your help.


  2. Are you insert DB in namespace

    namespace AppHttpControllers;
    use IlluminateHttpRequest;
    use IlluminateSupportFacadesDB;
    class PostsController extends Controller
    {
       public function show($slug)
        {
            $post = DB::table('posts')->where('slug', $slug)->first();
    
            if(! $post){
                abort(404);
            }
    
    
         return view('post', [
             'post' => $post
         ]);
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search