Skip to content

Instantly share code, notes, and snippets.

@Big-Shark
Last active November 20, 2015 09:37
Show Gist options
  • Save Big-Shark/8307231180b121da3830 to your computer and use it in GitHub Desktop.
Save Big-Shark/8307231180b121da3830 to your computer and use it in GitHub Desktop.
Install propel2 for laravel 5.1
  1. Create project
composer create-project laravel/laravel test-laravel-5-and-propel2 --prefer-source --dev --stability=dev
  1. Open dir
cd test-laravel-5-and-propel2
  1. Add propel integration package
composer require propel/propel-laravel:dev-develop
  1. Add providers
Propel\PropelLaravel\PropelIntegrationServiceProvider::class,
  1. Publish config
php artisan vendor:publish --provider 'Propel\PropelLaravel\PropelIntegrationServiceProvider'
  1. Create sample schema
php artisan propel:schema:create --sample
  1. Create simple database
mysql -u root
CREATE DATABASE sample_propel2;
  1. Change config
DB_HOST=localhost
DB_DATABASE=sample_propel2
DB_USERNAME=root
DB_PASSWORD=
  1. Remove standard migrations
rm -r database/migrations/*
  1. Create new migrations
php artisan propel:migration:diff
  1. Run migrations
php artisan propel:migration:up 
  1. Build a model
php artisan propel:model:build
  1. Test

  2. 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(); }); ```

  3. Start php server Shell php artisan serve

  4. Open url http://localhost:8000/

  5. Enjoy results.

Install debugbar

  1. Install package
composer require barryvdh/laravel-debugbar 
  1. Add provider
Barryvdh\Debugbar\ServiceProvider::class,
  1. Publish config
php artisan vendor:publish --provider ' Barryvdh\Debugbar\ServiceProvider'
  1. 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));
@k-vagin-parc
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment