Hey there,
I'm using illimunate/database with Slim Php and everything is working great except for observers. I've been migrating a project over from laravel and the observers work there, just not in slim php..
My config:
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'xxx',
'username' => 'xxx',
'password' => 'xxx',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'options' => array(
PDO::ATTR_CASE => PDO::CASE_LOWER
),
), 'default');
$capsule->setAsGlobal();
$capsule->bootEloquent();
Observer:
class UserObserver
{
public function saved($model)
{
//do something
}
}
//register
User::observe(new UserObserver);
This never gets run on a save. Any ideas?
Cheers,
Ben
Have you attach the event dispatcher?
I don't think so, any ideas on how to do that?
// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));
Read the doc https://github.com/illuminate/database
You should include composer require "illuminate/events" (with relevant version constraint).
Thanks for the reply, however I get the error:
PHP Fatal error: Class 'Illuminate\\Events\\Dispatcher' not found
When i try that :(
composer require "illuminate/events"
many thanks it's working great!
Most helpful comment
Read the doc https://github.com/illuminate/database
You should include
composer require "illuminate/events"(with relevant version constraint).