Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Created December 19, 2019 17:03
Show Gist options
  • Save DarkGhostHunter/7a90ed304d50ed53d7c1946d80e50d81 to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/7a90ed304d50ed53d7c1946d80e50d81 to your computer and use it in GitHub Desktop.
<?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