when create new record in fan model, @ same time create new fan record, want use new id value in column. i'm trying @ once , not have method go , update record.
$fan = fan::create([ 'display_name' => $displayname, 'bio' => $bio, 'logo_url' => $logourl, 'algolia_id' => 'fan_'??, // want replace ?? record's id value. ]); i've tried $fan, doesn't work since variable isn't created yet. cannot use auth because id isn't auth user's id.
thanks!
i doubt can automatically it, should in 2 steps:
$fan = fan::create([ 'display_name' => $displayname, 'bio' => $bio, 'logo_url' => $logourl ]); $fan->algolia_id = 'fan_' + $fan->id; $fan->save(); that said, it's not great database design, you'd rather want build algolia_id field when need use it, since you'd store duplicated value (the id , algolia_id same except fan_).
Comments
Post a Comment