Skip to content

Instantly share code, notes, and snippets.

@lukevers
Last active August 29, 2015 14:18
Show Gist options
  • Save lukevers/42beb9f00af6e713fa35 to your computer and use it in GitHub Desktop.
Save lukevers/42beb9f00af6e713fa35 to your computer and use it in GitHub Desktop.
App\Tips\Tip
<?php namespace App\Tips;
class NewUser extends Tip {
/**
* An array of tips.
*
* @var array
*/
protected $tips = [
'Use 1Password to generate your password',
'Make sure to save your account details',
];
}
<?php namespace App\Tips;
use Illuminate\Support\Collection;
class Tip {
/**
* The chosen tip.
*
* @var string
*/
protected $tip;
/**
* An array of tips.
*
* @var array
*/
protected $tips = [
'Write your own class that extends Tip'
];
/**
* Create a new Tip instance.
*
* @param array $tips
* @return void
*/
public function __construct($tips = null)
{
if (!is_null($tips))
{
$this->tips = $tips;
}
$this->handle();
}
/**
* Handle the tip.
*
* @return void
*/
public function handle()
{
$this->tip = Collection::make($this->tips)->random();
}
/**
* Print out a tip
*
* @return string
*/
public function __toString()
{
return $this->tip;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment