私はLaravel 5.2で簡単なユーザー登録を行い、本当に私を狂わせてしまいます。Laravel 5.2 - 登録
私はデフォルトのLaravelビルトイン登録システムから始めていくつかの追加フィールドを追加しました。
私の場合は、以下のファイルが含ま:
// Registration routes...
Route::get('auth/register', function(){
$organisations = Organization::all();
return view('auth.register', ['organizations' => $organisations]);
});
Route::post('auth/register', 'Auth\[email protected]');
routes.phpの
User.php
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['organization_id', 'team_id', 'lastname', 'firstname', 'login', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
/**
* Get the user's organisation.
*/
public function organization(){
return $this->belongsTo('App\Organization');
}
/**
* Get the user's team.
*/
public function team(){
return $this->belongsTo('App\Team');
}
}
Organization.php
をclass Organization extends Model
{
protected $table = 'organizations';
public $timestamps = false;
protected $fillable = ['name'];
/**
* Get the authors for the organization.
*/
public function users()
{
return $this->hasMany('App\Users');
}
/**
* Get the teams for the organization.
*/
public function teams()
{
return $this->hasMany('App\Teams');
}
}
Team.php
class Team extends Model
{
protected $table = 'teams';
public $timestamps = false;
/**
* Get the team's organisation
*/
public function organisation()
{
return $this->belongsTo('App\Organisation');
}
/**
* Get the authors for the team.
*/
public function users()
{
return $this->hasMany('App\Users');
}
}
AuthController.php
/
/.......
/......
/
/**
* 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, [
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'login' => 'required|max:255',
'organization' => 'required|max:255',
'team' => 'required|max:255',
'password' => 'required|confirmed|min:4',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'login' => $data['login'],
'organization_id' => $data['organization'],
'team_id' => $data['team'],
'password' => bcrypt($data['password']),
]);
}
私は、私の見解コードを投稿しません、私の入力が正しいです。
私の問題は、1人の新規ユーザーしか保存できないということです。何が起こっている
は次のとおりです。
- 私ユーザー表は
- 空である私は私のフォームを埋め、その後、私の最初のユーザー
それは(イェーイ)の作品を作成するためにそれを提出し、私は私のホームページに正しくリダイレクトされました
私は第2のユーザを作成したい
- 新しいユーザーが
- 私は私のテーブルで私のユーザーエントリを削除する(それは私が私のテーブルを空にする意味)した場合、私はホーム・ページが
にリダイレクトしています私のテーブルに格納されていない場合、私ができますもう一度新しいユーザーを作成してください。しかし、私は常に唯一のエントリを持つことができます。私はもっと追加することはできません。私はルートファイルでこれをしようとしただけで好奇心から
:
Route::get('/lol', function() {
return User::create([
'firstname' => 'what',
'lastname' => 'the',
'login' => 'f***',
'organization_id' => 1,
'team_id' => 4,
'password' => 'blabla',
]);
});
そしてもちろん、それは魔法のように私は/ルートを呼び出していますたびに動作します笑
だから何地獄この中で行われているAuthController?私は私の心の外ですか?
コントローラメソッドから2番目のユーザーを作成するときにエラーが発生しましたか? – Qazi