2015-10-15 35 views
0

在Laravel創建新用戶時5.1某些字段不節能 - Laravel 5.1註冊

user.php的

<?php 

namespace App; 

use Illuminate\Auth\Authenticatable; 
use Illuminate\Database\Eloquent\Model; 
use Illuminate\Auth\Passwords\CanResetPassword; 
use Illuminate\Foundation\Auth\Access\Authorizable; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; 
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 

class User extends Model implements AuthenticatableContract, 
           AuthorizableContract, 
           CanResetPasswordContract 
{ 
    use Authenticatable, Authorizable, CanResetPassword; 

/** 
* The database table used by the model. 
* 
* @var string 
*/ 
protected $table = 'laravel_users'; 

public $timestamps = false; 


protected $primaryKey = 'id'; 


/** 
* The attributes that are mass assignable. 
* 
* @var array 
*/ 
protected $fillable = [ 
        'username', 
        'password', 
        'role_id', 
        'email', 
        'avatar', 
        'isActive', 
       ]; 

/** 
* The attributes excluded from the model's JSON form. 
* 
* @var array 
*/ 
protected $hidden = ['password', 'remember_token']; 

public function isAdministrator() 
{ 
    return false; 
} 

public function blogs() 
{ 
    return $this->hasMany('App\Models\Blog'); 
} 
} 

authcontroller.php

我有一個問題
<?php 

namespace App\Http\Controllers\Auth; 

use Socialite; 
use Illuminate\Routing\Controller; 

#use App\Http\Controllers\Controller; 

use Redirect; 

use App\User; 
use Validator; 
use Auth; 
use Illuminate\Foundation\Auth\ThrottlesLogins; 
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; 

class AuthController extends Controller 
{ 
use AuthenticatesAndRegistersUsers, ThrottlesLogins; 

protected $redirectTo = '/admin'; 

public function __construct() 
{ 
    $this->middleware('guest', ['except' => 'getLogout']); 
} 
//temporarily redirected to duterte-run.mendanielle.com 
public function getRegister() 
{ 
    return view('auth.register'); 
} 
/** 
* Get a validator for an incoming registration request. 
* 
* @param array $data 
* @return \Illuminate\Contracts\Validation\Validator 
*/ 
protected function validator(array $data) 
{ 
    return Validator::make($data, [ 
     'username' => 'required|max:255', 
     'email' => 'required|email|max:255|unique:users', 
     'password' => 'required|confirmed|min:6', 
    ]); 
} 

/** 
* Create a new user instance after a valid registration. 
* 
* @param array $data 
* @return User 
*/ 
protected function create(array $data) 
{ 
    return User::create([ 
     'username' => $data['username'], 
     'email' => $data['email'], 
     'password' => bcrypt($data['password']), 
    ]); 
} 

/** 
* Redirect the user to the GitHub authentication page. 
* 
* @return Response 
*/ 

public function redirectToProvider() 
{ 

    return Socialite::with('facebook')->redirect(); 
} 

/** 
* Obtain the user information from GitHub. 
* 
* @return Response 
*/ 
public function handleProviderCallback() 
{ 

    //retrieve user's information from facebook 
    $user = Socialite::with('facebook')->user(); 
} 
} 

我不知道爲什麼電子郵件字段不存儲和PHP工匠修補程序返回沒有錯誤

此外,mysql字段是相關的CT和手動添加值內mysql命令works.Any想法呢?

+0

這是一個不工作的電子郵件/密碼用戶,或Github社交用戶? – andrewtweber

+0

@andrewtweber我創建了一個允許Github社交和傳統登錄形式的表單。我不知道它是否是正確的方式,因爲我是Laravel的新手,正如您所看到的,社交名稱的重定向和回調函數是'嵌入'在AuthController中,其中包含用戶的電子郵件/密碼。 –

回答

0

我的電子郵箱地址&沒有看到任何問題密碼。您在$fillable中有email屬性,並且您將其添加到create方法中,所以如果仍然存在問題,那麼您可能會錯誤地指定表單域。

如果您正在討論Socialite Github用戶,您的handleProviderCallback方法遠未完成。社會名流會給你一些用戶數據,但隨後就看你把這些數據並將其轉換成應用的用戶口才模型,並登錄該用戶。

public function handleProviderCallback() 
{ 
    $fb_user = Socialite::with('facebook')->user(); 

    // Check if the email is already registered 
    $user = User::where('email', '=', $fb_user->getEmail())->first(); 

    // If not, create a new user 
    if (! $user->exists) { 
     // Grab data from Facebook 
     $data = [ 
      'username' => $fb_user->getNickname(), 
      'email' => $fb_user->getEmail(), 
      'password' => str_random(40), 
     ]; 

     // Use it to create an Eloquent user object 
     $user = $this->create($data); 
    } 

    // Log that user in 
    \Auth::login($user); 

    // Direct them to the authenticated users page 
    return redirect('home'); 
} 

這仍然只是一個外殼,你」將不得不處理電子郵件/用戶名已被佔用的情況等。