1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
sexelleryoga/app/Models/Word.php
2020-10-03 16:07:18 +02:00

52 lines
1 KiB
PHP

<?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();
}
}