- Create project
composer create-project laravel/laravel test-laravel-5-and-propel2 --prefer-source --dev --stability=dev
- Open dir
cd test-laravel-5-and-propel2
- Add propel integration package
composer require propel/propel-laravel:dev-develop
- Add providers
Propel\PropelLaravel\PropelIntegrationServiceProvider::class,
- Publish config
php artisan vendor:publish --provider 'Propel\PropelLaravel\PropelIntegrationServiceProvider'
- Create sample schema
php artisan propel:schema:create --sample
- Create simple database
mysql -u root
CREATE DATABASE sample_propel2;
- Change config
DB_HOST=localhost
DB_DATABASE=sample_propel2
DB_USERNAME=root
DB_PASSWORD=
- Remove standard migrations
rm -r database/migrations/*
- Create new migrations
php artisan propel:migration:diff
- Run migrations
php artisan propel:migration:up
- Build a model
php artisan propel:model:build
-
Test
-
Update route file ```php Route::get('/', function () {
$book = new \App\Models\Book(); $book->setTitle('My Heros'); $book->setIsbn('123154');
$author = new \App\Models\Author(); $author->setFirstName('Hans'); $author->setLastName('Zimmer');
$publisher = new \App\Models\Publisher(); $publisher->setName('World');
$book->setPublisher($publisher); $book->setAuthor($author); $book->save();
return $book->toArray(); }); ```
-
Start php server
Shell php artisan serve
-
Open url http://localhost:8000/
-
Enjoy results.
Install debugbar
- Install package
composer require barryvdh/laravel-debugbar
- Add provider
Barryvdh\Debugbar\ServiceProvider::class,
- Publish config
php artisan vendor:publish --provider ' Barryvdh\Debugbar\ServiceProvider'
- Add boot method for AppServiceProvider
$connectionWrapper = \Propel\Runtime\Propel::getServiceContainer()->getConnection();
//$connectionWrapper->setLogMethods(['__construct', 'beginTransaction', 'commit', 'rollBack', 'forceRollBack', 'prepare', 'exec', 'query', '__destruct']);
$traceablePdo = new \DebugBar\DataCollector\PDO\TraceablePDO($connectionWrapper->getWrappedConnection());
$this->app['debugbar']->addCollector(new \DebugBar\DataCollector\PDO\PDOCollector($traceablePdo));
In my case, the boot method of AppServiceProvider (AppServiceProvider::boot) calls before init of propel services, that leads to this error: "No connection defined for database "default"... bla bla bla"
I created a new service provider, registered in config/app.php, and I put code from "Add boot method for AppServiceProvider" into this new provider's boot method. After this, problem disappeared.