Laravel MySQL PHP

Laravel Eloquent Model Events

Hi All ,

In this post , I’ll talk about Eloquent Model Events.

Looks Like Database Trigger Isn’t it?

When I read the documentation , I said “Mysql already doing this so..”. Personally, still I prefer to use Mysql Triggers for database operations. It’s more faster and guaranteed. But day by day NoSQL solutions or Hybrid database solutions like using MongoDB and Mysql together becoming as a popular solutions.  Also each NoSQL database is different, but MongoDB doesn’t support  actually stored procedures or triggers. In that case , we need to handle this kind of situations.

If you are interested in MySQL-NoSQL Hybrid Solution with Laravel. You can check this package by Jessenger.

For More

Laravel site has a simple usage example for Eloquent Model Events for “Validation”. In real projects , we have to validate every input , when model “updating” and “creating” its very important. So, Model Events is amazingly useful for this job. You can check the JeffreyWay Model Validation package from github.  This package supports model based validation rules.

Generaly, we need to delete photos , avatars , attachments from FTP too or Logging Model actions We can add more usages examples depends on situation. Let’s see abilities of Model Events.