Archived
1
0
Fork 0

Initial Commit

This commit is contained in:
Henrik Hautakoski 2020-10-03 16:07:18 +02:00
commit 9b22323711
36 changed files with 7164 additions and 0 deletions

52
app/Models/Word.php Normal file
View 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();
}
}