Flush and reset Eloquent model events when testing.
September 9, 2014 ยท View on GitHub
resetEvents();
}
/**
* Flush and reboot Eloquent model events.
*
* @return void
*/
public function resetEvents()
{
foreach ($this->getModels() as $model)
{
call_user_func([$model, 'flushEventListeners']);
call_user_func([$model, 'boot']);
}
}
/**
* Get the model names from their filename.
*
* @return array
*/
protected function getModels()
{
$files = File::files(base_path() . '/app/models');
foreach ($files as $file)
{
$models[] = pathinfo($file, PATHINFO_FILENAME);
}
return $models;
}
}