Skip to content

Instantly share code, notes, and snippets.

@joaorobertopb
Last active May 5, 2018 20:18
Show Gist options
  • Save joaorobertopb/a28f51a334f21502719493dc1b2179ba to your computer and use it in GitHub Desktop.
Save joaorobertopb/a28f51a334f21502719493dc1b2179ba to your computer and use it in GitHub Desktop.
Exemplo de código utilizado em um dos meus artigos: medium.com/@joaorobertopb
<?php
//Trecho de código, retirado de https://github.com/laravel/framework/blob/5.6/src/Illuminate/Database/Eloquent/Model.php#L189
/**
* The "booting" method of the model.
*
* @return void
*/
protected static function boot()
{
static::bootTraits();
}
/**
* Boot all of the bootable traits on the model.
*
* @return void
*/
protected static function bootTraits()
{
$class = static::class;
foreach (class_uses_recursive($class) as $trait) {
if (method_exists($class, $method = 'boot'.class_basename($trait))) {
forward_static_call([$class, $method]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment