Support the ongoing development of Laravel.io →
Eloquent
Last updated 2 years ago.
0

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));
}	

}

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.