ジョーSCOTTO:
内のユーザーを作成するときUser.php
、私は、UUIDを定義するディレクトリを作成し、DB上のユーザーにそれを追加しようとしています。フォルダには、UUIDで正常に作成されますが、それはに渡され得ることはありませんcreating()
コールバック。
/**
* Create the user when this class is called
*
* @return void
*/
public static function boot()
{
// Setup parent
parent::boot();
// Create UUID
$uuid = Str::uuid();
// Create user directory on S3
Storage::disk('s3')->makeDirectory('users/' . $uuid);
// Assign UUID to new user
self::creating(function ($model) {
$model->id = $uuid;
});
}
$model->id = $uuid;
無価値にここで、結果は未定義です。
Tsakhog:
注入し$uuid
、このような閉鎖へ:
self::creating(function ($model) use ($uuid) {
$model->id = $uuid;
});