How does laravel "WithoutModelEvents" work?
How does this gets called???
WithoutModelEvents ...
1trait WithoutModelEvents
2{
3 /**
4 * Prevent model events from being dispatched by the given callback.
5 *
6 * @param callable $callback
7 * @return callable
8 */
9 public function withoutModelEvents(callable $callback)
10 {
11 return fn () => Model::withoutEvents($callback);
12 }
13}
Well, it is quite underwhelming, it is hard coded...
src/Illuminate/Database/Seeder.php:181 ...
1public function __invoke(array $parameters = [])
2{
3 ...
4
5 $uses = array_flip(class_uses_recursive(static::class));
6
7 if (isset($uses[WithoutModelEvents::class])) {
8 $callback = $this->withoutModelEvents($callback);
9 }
10
11 ...
12}
2025-10-06 07:46:14