2017-09-16 76 views
-2

enter image description here未定義指數laravel

我已經(0)專家設置的默認值,當我檢查專家複選框,其在數據庫專家列節省1。但是當我不檢查那個盒子時,它會返回未定義索引的錯誤。

enter image description here

+0

顯示您正在嘗試的一些示例代碼 – Michel

+0

它從sql中沒有錯誤。它從php代碼中的錯誤。你已經爲sql表列設置了默認值。所以你必須檢查值是否設置爲 – Vinothini

+0

向我們顯示你的代碼。屏幕截圖沒有用。 –

回答

1

如果選中該複選框意味着它會給值,否則它不會給任何價值

試試這個

(isset($data['expert']) ? $data['expert'] : '0'); 
+1

如果(isset($ _ POST [ 「專家」])){ 回報用戶::創建([ 我的數據 '專家'=> $ _ POST [ 「專家」] ]); } 其他{ 回報用戶::創建([ 我的數據 ]); } –

0

如果(isset($ _ POST [ 「專家」]) ){

 return User::create([ 
      'name' => $data['name'], 
      'email' => $data['email'], 
      'password' => bcrypt($data['password']), 
      'username' => $data['username'], 
      'dob' => $data['dob'], 
      'expert'=>$_POST["expert"] 

     ]); 
    } 
    else{ 
     return User::create([ 
      'name' => $data['name'], 
      'email' => $data['email'], 
      'password' => bcrypt($data['password']), 
      'username' => $data['username'], 
      'dob' => $data['dob'] 
      ]); 

    }