【发布时间】:2016-01-20 15:40:33
【问题描述】:
我的身份验证和一切正常。我可以登录/注销等。我有两张表,一张称为用户,这是默认的身份验证,第二张称为播放器,将用于播放器数据。我做了一个 Player 模型。
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Player extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'players';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['username', 'wood'];
}
并将 AuthController 类编辑为:
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* 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|min:4|max:32|unique:players',
'name' => '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([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
return Player::create([
'username' => $data['username'],
'wood' => 0,
]);
}
}
当我注册一个新用户时,用户数据会在 users 表中创建,但我的 player 表没有任何反应。它只是空的。
【问题讨论】:
-
我将此标记为需要编辑;但是,更具体地说:您应该证明您为诊断问题所做的工作……比`...更具信息性的东西...但是我的玩家表没有任何反应。它只是空的。”将使 SO 社区更容易为您提供帮助。
标签: php laravel authentication laravel-5.1