2017-10-07 117 views
0

我正在使用模板adminlte ..但我想使用由adminlte提供的註冊控制器,但我有一個問題..當我想註冊..我有兩個選項卡..第一標籤是客戶,第二個標籤是驅動程序。 Laravel如何使用註冊控制器

的probelem是我no identitas column

這是我registerController

protected function create(array $data) 
{ 
    $fields = [ 
     'name'   => $data['name'], 
     'email'   => $data['email'], 
     'password'  => bcrypt($data['password']), 
     'phone'   => $data['phone'], 
     'gender'  => $data['gender'], 
     'no_identitas' => $data['no_identitas'], 
    ]; 
    $activation = Activation::create([ 
     'code' => str_random(20), 
    ]); 

    $user = User::create($fields); 
    $user->activation()->save($activation); 
    if($data['no_identitas']){ 
     $porter = Porter::create($fields); 
     $porter->user()->save($user);  
    }else{ 
     $customer = Customer::create($fields); 
     $customer->user()->save($user); 
    } 
    return $user; 
} 

我,當我嘗試存儲客戶數據,因爲在客戶表的錯誤,我沒有no_identitas列

+0

有幾種解決方案,您的問題。我的兩分錢將是:'$ model-> no_identitas = NULL',如果你的列是'可空'的。你有兩種'用戶'。我的建議是:用'no_identitas'創建一個新表,並創建一個新的列,說明用戶類型:'user'或'customer'。當你想顯示關於用戶/客戶的信息時,你應該首先檢查他們是否是'用戶'或'客戶'。 –

回答

0

正如我在評論中提到的,您有兩種選擇。

輕鬆一

no_identitas = NULL。假設你的列是可空的。

哈德AKA正確的:

你應該有一個有兩個值的enum類型:usercustomer。當存儲數據,你應該首先檢查用戶是否是user or customer

if($user->type == 'user'){ 
    $user->no_identitas = $no_identitas 
}else{ 
    $user->no_identitas = NULL 
} 

顯示當您應該檢查從哪個用戶正在從顯示數據的數據:

if($user->type == 'user'){ 
    {{ $user->no_identitas }} 
}else{ 
    <h2> This user has no identitas </h2> 
} 
相關問題