It works
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class Test extends Model{
protected $fillable = ['text'];
public static function boot()
{
parent::boot();
parent::observe(new \App\Http\Observers\TestObserver);
}
}
But when i put this code on a Service Provider... dont works...
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class TesteServiceProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
\App\Test::observe(new \App\Http\Observers\TestObserver);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
my app.php
'providers' => [
/*
* Application Service Providers...
*/
'App\Providers\AppServiceProvider',
'App\Providers\EventServiceProvider',
'App\Providers\RouteServiceProvider',
'App\Providers\CourseServiceProvider',
'App\Providers\TestServiceProvider',
Someone knows why?
The resolution I found was to create an ObserverServiceProvider and place it after DatabaseServiceProvider in the config/app.php file.
Because the event dispatcher is attached to the base Model class in DatabaseServiceProvider. Once event is dispatched in DatabaseServiceProvider we can use Observer.
You looked at the event solution that comes as part of L5?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community