#database #development #eloquent #laravel #php
Stop all inbuilt model dispatch events for a specific model.
Advantage: applications will take less memory and improve performance.
Disadvantage: you can not use the Observer class for that model.
1namespace App\Models;
2
3class User extends Model
4{
5 // First way: by using a static property
6 public static $dispatcher = null;
7
8 // Second way: in the constructor
9 public function __construct()
10 {
11 // if (!App::isLocal()) {
12 self::unsetEventDispatcher();
13 // }
14 }
15
16}
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.