title: How to make SQLite work in Laravel
body: <p>Whenever I run <code>php artisan migrate</code>, the following error is shown in the console:</p>
  
  <blockquote>
    <p>[PDOException]<br>
      SQLSTATE[HY000] [14] unable to open database file</p>
  </blockquote>
  
  <p>The <em>database.sqlite</em> file is located at <em>database/</em>. I'm running <em>Windows 10</em>, <em>Laravel 5.2</em>. Here is <em>.env</em> file config:<br></p>
  
  <h2><strong>.env:</strong></h2>
  
  <pre><code>DB_CONNECTION=sqlite
  DB_HOST=127.0.0.1
  DB_PORT=3306
  DB_DATABASE=database
  DB_USERNAME=homestead
  DB_PASSWORD=secret
  </code></pre>
  
  <p>I have looked everywhere, but could not find what causes this error and how to resolve it.</p>
  
  <h2>Update</h2>
  
  <p>I managed to make migrations run successfully by replacing <code>DB_DATABASE=database</code> with <code>DB_DATABASE=database/database.sqlite</code> in <em>.env</em> file. However, new error occurs whenever I try to retrieve items from the database:</p>
  
  <pre><code>public function index()
  {
      // cause of the error
      $cards = Card::all();
  
      return view('cards.index', compact('cards'));
  }
  </code></pre>
  
  <p>The above action throws following error:</p>
  
  <blockquote>
    <p>InvalidArgumentException in SQLiteConnector.php line 34:<br>
    Database (database/database.sqlite) does not exist.</p>
  </blockquote>
  
  <p>The strange thing is, that the command <code>Card::all()</code> works flawlessly in <code>php artisan tinker</code> mode. What kind of magic is that?</p>
  
  <p>Anyway, I've also found out, that the line:</p>
  
  <pre><code>'database' =&gt; env('DB_DATABASE', database_path('database.sqlite')),
  </code></pre>
  
  <p>in <em>database.php</em> file needs to be replaced with just <code>database_path('database.sqlite')</code> and <strong>everything starts to work normally</strong>.</p>
  
  <hr>
  
  <p>It seems, that the root of the problem is <code>env('DB_DATABASE')</code> call. I went to <em>SQLiteConnector.php</em> file and dumped the output of both <code>env('DB_DATABASE')</code> and <code>database_path('database.sqlite')</code>. Here are their outputs respectively:</p>
  
  <pre><code>dd(env('DB_DATABASE'))               // =&gt; 'database/database.sqlite'
  dd(database_path('database.sqlite')) // =&gt; 'D:\www\project\database\database.sqlite'
  </code></pre>
  
  <p>As you see, their output differs, and the second one is what is expected. Is this a Laravel bug? Or did I misunderstood something?</p>