ich eine Frage Modell wie dieses:Laravel Mutator, die eine eindeutige Zufallszahl erzeugt wird nicht ausgeführt
class Question extends Model
{
use SoftDeletes;
protected $primaryKey = 'question_id';
protected $dates = ['deleted_at'];
protected $fillable = ['text', 'code', 'cat', 'answer', 'is_private', 'email', 'parent'];
public function setCodeAttribute ($value)
{
\Debugbar::info('hello');
do {
$code = rand(10000, 10000000);
$user_code = User::where('code', $code)->get();
} while (!$user_code->isEmpty());
return $this->attributes['code'] = $code;
}
}
Ich möchte eine zufällige ganze Zahl erzeugen und speichern, dass in code
Feld auf Schaffung einer neuen Instanz das Model.
Dafür schrieb ich einen Mutator, wie Sie sehen können, aber es lief nicht einmal.
Was ist ein Problem?