Created
May 18, 2018 22:00
-
-
Save whoisryosuke/f1748932010c51ca35660d5097abd29a to your computer and use it in GitHub Desktop.
Laravel - Add a hook script to the Model. In this case, we generate a UUID on creation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Setup model event hooks | |
*/ | |
public static function boot() | |
{ | |
parent::boot(); | |
self::creating(function ($table) { | |
// Generate uuid | |
$table->uuid = Uuid::generate(4); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment