A
A
Andreo2015-08-27 16:20:44
Laravel
Andreo, 2015-08-27 16:20:44

eloquent events not working in laravel 4.2. What am I doing wrong?

I understand this framework.
I took a solution from a bunch of manuals and inserted the following lines into the model under a blueprint to process model events:

public static function boot() {

    parent::boot();

    static::creating(function($model) {
      $model->firm_hash = md5(str_random(25));
      return true;
    });
    
    static::updating(function($model){
      $model->firm_colors = 'ddddddddd';
    });
  }

In the routes we have the following:
Route::get('/test/update-firm-colors/{firm_id}', function($firm_id){
  $firm = BusinessFirm::find($firm_id);
  $firm->firm_colors = str_random(6); // Для теста
  $firm->save();
  return Response::json($firm);
});

As a result, it is not clear why the firm_colors attribute does not change when the model is updated, and when a new model is added, static::creating works fine.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2015-08-27
@Denormalization

I specially downloaded L4.2 to check - everything works as it should.
So the error is somewhere else. You need to go all the way step by step and see why it does not work. (Although 80% that everything works as it should, but you are looking in the wrong direction).
PS
Why use 4.2? It has not been relevant for a long time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question