Lumen 5.x integration
To install TDBM in Lumen 5.x:
composer require thecodingmachine/tdbm-laravel ^5.0
Then edit your bootstrap/app.php
file and register the service provider:
$app->register(TheCodingMachine\TDBM\Laravel\Providers\TdbmServiceProvider::class);
When installation is done, you need to generate DAOs and beans from your data model.
Run the following command:
php artisan tdbm:generate
By default, TDBM will write DAOs in the App\Daos
namespace and beans in the App\Beans
namespace.
If you want to customize this, you can edit the bootstrap/app.php
file:
config([
'tdbm.daoNamespace' => 'App\\Daos',
'tdbm.beanNamespace' => 'App\\Beans'
]);
In Lumen, you would typically inject the DAOs in your route closure.
bootstrap/app.php
use App\Daos\UserDao;
// ...
$app->get('test', function(UserDao $userDao) {
$user = $this->userDao->getById($id);
// do stuff
});
Alternatively, if you use controllers, you can also inject the DAOs in your controllers constructor (or in any class resolved by the Lumen container).
Typically:
bootstrap/app.php
$app->get('test', [
'uses' => 'TestController@index'
]);
app/Http/Controllers/TestController.php
<?php
namespace App\Http\Controllers;
use App\Daos\MigrationDao;
use Illuminate\Http\Request;
class TestController extends Controller
{
/**
* @var UserDao
*/
private $userDao;
/**
* The DAO we need is injected in the constructor
*/
public function __construct(UserDao $userDao)
{
$this->userDao = $userDao;
}
public function index($id)
{
$user = $this->userDao->getById($id);
// do stuff
}
}
Let's now learn how to access the database.
Found a typo? Something is wrong in this documentation? Just fork and edit it!