I'm trying to utilize the Laravel database contract instead of the facade (DB::table) and getting:
ReflectionException
Class Illuminate\Contracts\Database does not exist
Using the Illuminate\Database\DatabaseManager class works fine, but I would prefer not use a concrete class but rather an abstract class (contract/interface) in addition to dependency injection.
Here's what I've tried.
Controller:
<?php namespace App\Http\Controllers;
use Illuminate\Contracts\Database as DB;
class MyController extends Controller
{
public function __construct(DB $db)
{
$this->db = $db;
}
}
AppServiceProvider:
public function register()
{
$this->app->bind(
'Illuminate\Contracts\Auth\Registrar',
'App\Services\Registrar',
'Illuminate\Contracts\Database'
);
}
Any help appreciated!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire