unguarded() публичный статический Метод

Run the given callable while being unguarded.
public static unguarded ( callable $callback ) : mixed
$callback callable
Результат mixed
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->resolver->setDefaultConnection($this->getDatabase());
     Model::unguarded(function () {
         $this->getSeeder()->run();
     });
 }
 /**
  * @return mixed
  */
 public function handle()
 {
     // TODO: Implement handle() method.
     if (!$this->confirmToProceed()) {
         return;
     }
     $this->resolver->setDefaultConnection($this->getDatabase());
     Model::unguarded(function () {
         $this->getSeeder()->run();
     });
 }
Пример #3
0
 /**
  * Make an instance of the model with the given attributes.
  *
  * @param  array $attributes
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function makeInstance(array $attributes = [])
 {
     return Model::unguarded(function () use($attributes) {
         if (!isset($this->definitions[$this->class][$this->name])) {
             throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}].");
         }
         $definition = call_user_func($this->definitions[$this->class][$this->name], $this->faker);
         return new $this->class(array_merge($definition, $attributes));
     });
 }
Пример #4
0
 public function testUnguardedCallDoesNotChangeUnguardedStateOnException()
 {
     try {
         Model::unguarded(function () {
             throw new Exception();
         });
     } catch (Exception $e) {
         // ignore the exception
     }
     $this->assertFalse(Model::isUnguarded());
 }