thanks to http://stackoverflow.com/users/1010632/david-barker now I got the answer : this is my observer :
class NewsObserver {
protected $events;
public function __construct(Dispatcher $dispatcher)
{
$this->events = $dispatcher;
}
public function saving($model)
{
if ($model->isDirty(['publish']))
{
$this->changeState($model->publish);
}
}
public function changeState($value)
{
echo 'event fired and I got it';
}
}
and this is my model
use Illuminate\Events\Dispatcher; class News extends Magniloquent {
protected $fillable = [];
public $table = 'news';
public static function boot()
{
parent::boot();
News::observe(new NewsObserver(new Dispatcher));
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community