Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable
<p>I'm using Eloquent in combination with Slim Framework to build a small API. For some reason, I am getting this error, and I can't locate the problem:</p>
<pre><code>Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.
</code></pre>
<p>Database settings are correct. This error is thrown in my staging environment on the server. Locally, with MySQL 5.6.29, it works perfectly. Although I don't think it's related to MySQL 5.7 because I have another app running on the same server with the same version of Eloquent.</p>
<p>Can anyone point me in the right direction?</p>
<p>I'm using:</p>
<ul>
<li>Eloquent Version: <strong>5.3.23</strong></li>
<li>PHP Version: <strong>5.6.28</strong></li>
<li>Database Driver &amp; Version: MySQL <strong>5.7.16</strong></li>
</ul>
<p>Backtrace</p>
<pre><code>/path/to/app/shared/vendor/illuminate/container/Container.php:644 
Illuminate\Container\Container -&gt; make
/path/to/app/shared/vendor/illuminate/database/Connectors/ConnectionFactory.php:130 
call_user_func 
/path/to/app/shared/vendor/illuminate/database/Connection.php:964 
Illuminate\Database\Connection -&gt; getPdo 
/path/to/app/shared/vendor/illuminate/database/Connection.php:832 
Illuminate\Database\Connection -&gt; reconnectIfMissingConnection 
/path/to/app/shared/vendor/illuminate/database/Connection.php:717 
Illuminate\Database\Connection -&gt; run 
/path/to/app/shared/vendor/illuminate/database/Connection.php:350 
Illuminate\Database\Connection -&gt; select 
/path/to/app/shared/vendor/illuminate/database/Query/Builder.php:1648 
Illuminate\Database\Query\Builder -&gt; runSelect 
/path/to/app/shared/vendor/illuminate/database/Query/Builder.php:1634 
Illuminate\Database\Query\Builder -&gt; get 
/path/to/app/shared/vendor/illuminate/database/Eloquent/Builder.php:632 
Illuminate\Database\Eloquent\Builder -&gt; getModels 
/path/to/app/shared/vendor/illuminate/database/Eloquent/Builder.php:327 
Illuminate\Database\Eloquent\Builder -&gt; get 
/path/to/app/shared/vendor/illuminate/database/Eloquent/Builder.php:297 
Illuminate\Database\Eloquent\Builder -&gt; first 
...
</code></pre>
<p>I'm suspecting it has something to do with an unregistered error handler:</p>
<p><a href="https://github.com/laravel/laravel/blob/master/bootstrap/app.php#L39-L42" rel="nofollow noreferrer">github link</a></p>
<p>But how can I register the custom error handler when not using Laravel?</p>
<p>The solution of @patricus can be implemented as follows:</p>
<pre><code>// bootstrap Eloquent ORM
$container = new Container();
$container-&gt;singleton(
  'Illuminate\Contracts\Debug\ExceptionHandler'
, 'My\Custom\DatabaseExceptionHandler'
);

$factory    = new ConnectionFactory( $container );
$connection = $factory-&gt;make([
  'driver'    =&gt; 'mysql'
, 'host'      =&gt; App::config( 'database_host' )
, 'database'  =&gt; App::config( 'database_name' )
, 'username'  =&gt; App::config( 'database_user' )
, 'password'  =&gt; App::config( 'database_password' )
, 'charset'   =&gt; App::config( 'database_charset' )
, 'collation' =&gt; App::config( 'database_collate' )
, 'prefix'    =&gt; ''
]);

$resolver = new ConnectionResolver();
$resolver-&gt;addConnection( 'default', $connection );
$resolver-&gt;setDefaultConnection( 'default' );

// initialize connection
Model::setConnectionResolver( $resolver );
</code></pre>