Laravel中未定义的偏移量问题

时间:2019-09-19 10:09:14

标签: php laravel

任何好友在这里帮助我 我面临抵消问题。

$cookie = Cookie::get('referral');

$referred_by = $cookie ? \Hashids::decode($cookie)[0] : null;

return User::create([
    'name' => $data['name'],
    'email' => $data['email'],
    'password' => Hash::make($data['password']),
    'referred_by' => $referred_by
]);

1 个答案:

答案 0 :(得分:1)

$cookie = Cookie::get('referral');

$referred_by = $cookie ? (isset(\Hashids::decode($cookie)[0]) ?? null) : null;

return User::create([
    'name' => $data['name'],
    'email' => $data['email'],
    'password' => Hash::make($data['password']),
    'referred_by' => $referred_by
]);