Initial Commit
This commit is contained in:
commit
9b22323711
36 changed files with 7164 additions and 0 deletions
52
app/Models/Word.php
Normal file
52
app/Models/Word.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Word extends Model
|
||||
{
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Get the route key for the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'uuid';
|
||||
}
|
||||
|
||||
static public function boot()
|
||||
{
|
||||
static::saving(function($model) {
|
||||
$model->uuid = substr(base64_encode($model->value), 0, 10);
|
||||
});
|
||||
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a random row from the table.
|
||||
*
|
||||
* @var mixed $exclude uuid's of rows that should be excluded.
|
||||
*/
|
||||
static public function getRandom($exclude = [])
|
||||
{
|
||||
$q = self::inRandomOrder();
|
||||
|
||||
if (!is_array($exclude)) {
|
||||
$exclude = [ $exclude ];
|
||||
}
|
||||
if (count($exclude) > 1) {
|
||||
$q->where("uuid", 'NOT IN', $exclude);
|
||||
}
|
||||
return $q->first();
|
||||
}
|
||||
}
|
||||
Reference in a new issue