#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}