Created
December 19, 2019 17:03
-
-
Save DarkGhostHunter/7a90ed304d50ed53d7c1946d80e50d81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace App; | |
use Illuminate\Support\Facades\Log; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Str; | |
trait HasToken | |
{ | |
/** | |
* Boot the trait | |
* | |
* @return void | |
*/ | |
protected function bootHasToken() | |
{ | |
static::created(function ($model) { | |
// Log who created this model | |
Log::info('Token for ' . class_basename($model) . ' created by ' . Auth::user()->getKey()); | |
}); | |
} | |
/** | |
* Initialize the trait | |
* | |
* @return void | |
*/ | |
protected function initializeHasToken() | |
{ | |
// Automatically create a random token | |
$this->token = Str::random(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment