错误:从空值创建默认对象 - Laravel5.5

时间:2018-02-21 14:19:58

标签: php laravel-5 controller routes

感谢您过去的所有帮助。我最近在尝试在我的应用上注册新用户时遇到此错误。在注册的这个阶段,新用户 - 在验证了电子邮件地址后 - 现在被要求输入他购买的PIN。单击验证引脚时,会发生以下错误:

  

错误:从空值创建默认对象

此错误指向我的RegisterController行216.以下是我的控制器中有故障和路由的部分:

public function postPurchaseToken(Request $request)
  {
    $this->validate($request,['pin' => [
        'required',
        Rule::exists('activation_pins','pin')->where(function ($query) {
            $query->where('usage_count', '<', ActivationPin::MAX_USAGE_COUNT)
            ->where('is_valid',true)
            ->where('is_active',false);
        })
    ]]);

    $user = auth()->user();

    $pin = ActivationPin::wherePin($request->pin)->first();

    $pin->is_active = true;
    $pin->user_id = $user->id;
    $pin->save();

    $user->is_token_activated = true;
    $user->purchase_expiration_date = null;
    $user->save();

    return redirect()->to('/register/verify-phone-number');
}

第216行:$pin->is_active = true;

路线:

Route::get('/register/verify/{email_confirmation_code}','Auth\RegisterController@confirmEmail')->name('confirm-account');
Auth::routes();
Route::get('/register/purchase-token','Auth\RegisterController@getPurchaseToken');
Route::post('/register/purchase-token','Auth\RegisterController@postPurchaseToken');
Route::get('/register/verify-phone-number/{token_id?}','Auth\RegisterController@getPhoneNumber');
Route::get('/register/verify-phone-number','Auth\RegisterController@getPhoneNumber');
Route::post('/register/call-phone-number/{token_id}','Auth\RegisterController@postSendAsCall');
Route::post('/register/verify-phone-number','Auth\RegisterController@postPhoneNumber');

Route::post('/register/verify-phone-number','Auth\RegisterController@postPhoneNumber');

Route::post('/register/send-verification-sms','Auth\RegisterController@postSendSMSToPhoneNumber');
Route::get('/register/bank-details','Auth\RegisterController@getBankDetails');
Route::post('/register/bank-details','Auth\RegisterController@postBankDetails');
Route::get('/register/select-plan','Auth\RegisterController@getSelectPackage');
Route::post('/register/select-plan','Auth\RegisterController@postSelectPackage');
Route::get('/logout', 'Auth\LoginController@logout')->name('logout.get');

我很感激我能得到的任何帮助。感谢

0 个答案:

没有答案