1static::creating(function ($model) {
2 if (!Seeder::isRunning()) {
3 // do something only when the seeder is not running
4 }
5})
6
7 // Add helper into your project
8
9 class Seeder
10{
11 protected static $running = false;
12
13 public function isRunning()
14 {
15 return static::$running;
16 }
17
18 public function start()
19 {
20 static::$running = true;
21 }
22
23}
24
25
26// and than in your DatabaseSeeder class:
27
28public function run()
29{
30 Seeder::start();
31 /* your seeder coder */
32}