Laravel 5 某些字段未保存-Laravel 5.1注册
在Laravel 5.1中创建新用户时出现问题 User.phpLaravel 5 某些字段未保存-Laravel 5.1注册,laravel-5,Laravel 5,在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
<?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');
}
}
我看不出您的电子邮件和密码有任何问题。您在$filleble
中有email
属性,并将其添加到create
方法中,因此如果仍然存在问题,则可能表单字段的名称不正确
如果您谈论的是社交名流Github用户,那么您的handleProviderCallback
方法还远远没有完成。社交名媛会给你一些用户数据,但接下来就要由你来获取这些数据,并将其转换为你应用程序的用户口才模型,然后登录该用户
公共函数handleProviderCallback()
{
$fb_user=Socialite::with('facebook')->user();
//检查电子邮件是否已注册
$user=user::where('email','=',$fb_user->getEmail())->first();
//如果没有,请创建一个新用户
如果(!$user->存在){
//从Facebook抓取数据
$data=[
'username'=>$fb_user->get昵称(),
'email'=>$fb_user->getEmail(),
“密码”=>str_random(40),
];
//使用它创建一个有说服力的用户对象
$user=$this->create($data);
}
//登录该用户
\Auth::login($user);
//将他们引导到“已验证用户”页面
返回重定向(“主页”);
}
这仍然只是一个外壳,您必须处理电子邮件/用户名已被占用的情况,等等。是电子邮件/密码用户不起作用,还是Github社交名流用户?@andrewtweber我创建了一个表单,允许Github社交名流和传统登录到一个表单中。我不知道这是不是正确的方式,因为我是Laravel的新手,如您所见,社交名流的重定向和回调函数“嵌入”在AuthController中,其中包含用户的电子邮件/密码。
<?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();
}
}