title: Laravel 8 – Eloquent Queries Without Database Migration
body: <p>I’m a newbie with Laravel, but old school PHP developer. I’m in the process of adapting my framework to the Laravel framework.</p>
  <p>My main goal at this moment is to use eloquent queries without doing a DB schema and migration inside Laravel, as I have my database is built already, up and running.</p>
  <p>So far, I’ve been successful in using eloquent queries to interact with my database. Here’s a part of the code that’s working without any problems:</p>
  <pre><code>$results = DB::table('my_table')-&gt;where('id', '=', 123)-&gt;orderBy('title')-&gt;get()-&gt;toArray();
  </code></pre>
  <p>The problem is when I try to limit the fields I want to retrieve from the database. So far, I’ve tried:</p>
  <pre><code>-&gt;select('id', 'title', 'description')
  </code></pre>
  <p>and</p>
  <pre><code>-&gt;get('id', 'title', 'description')
  </code></pre>
  <p>It returns me an error like so:</p>
  <blockquote>
  <p>Illuminate\Database\QueryException
  SQLSTATE[42S22]: Column not found: 1054 Unknown column ' title' in 'field list' (SQL: select <code>id</code>, <code> title</code>, <code> description</code> from <code>categories</code> where <code>id_parent</code> = 781 and <code>activation</code> = 1 order by <code>title</code> asc)
  A column was not found
  You might have forgotten to run your migrations. You can run your migrations using php artisan migrate.
  Pressing the button below will try to run your migrations.**</p>
  </blockquote>
  <p>I know that I could probably accomplish this through raw queries, but my intention is to use some of Laravel´s features that are widely used in tech companies. So, is it even possible to accomplish what I’m trying to using eloquent queries without having to build a DB schema and all migration process? And if so, what would be the way?</p>
  <p>One of the main reasons I don’t want to develop a migration and schema is that my database has a prefix for the tables inside my framework that I change according to each project / client and I don’t want to spend some time on how I could build a migration / schema with a prefix and so on.</p>
  <p>I´ve checked this stackoverflow link:
  <a href="https://stackoverflow.com/questions/34428002/laravel-without-eloquent-database-migrations">Laravel without Eloquent &amp; database migrations?</a>
  But it wasn’t quite what I was looking for.</p>
  <p><strong>Edit - Solution:</strong>
  The problem was with a bug that had extra space on the column name. So, the following worked:</p>
  <pre><code>$results = DB::table('my_table')-&gt;select('id', 'title', 'description')-&gt;where('id', '=', 123)-&gt;orderBy('title')-&gt;get()-&gt;toArray();
  </code></pre>