アプリに Laravel 4 を使用しています。このアプリには、購入者とユーザーの 2 つの認証モデルがあります。このモデルにはまったく異なるロジックがあるため、User->type フィールドは使用しません。
これが私のログインコントローラーです:
public function postIndex()
{
if (Auth::attempt(array_only(Input::get(), array('email', 'password')), array_only(Input::get(), array('save')))) {
Login::create(array('user_id' => Auth::user()->id, 'session_id' => session_id())); // Создаем новую запись логина вместе с session_id.
return Redirect::to('/');
}
return $this->userauth();
}
public function userauth() {
Config::set('auth.model', 'User');
Config::set('auth.table', 'users');
$test = Config::get('auth.model');
if (Auth::attempt(array_only(Input::get(), array('email', 'password')), array_only(Input::get(), array('save')))) {
Login::create(array('user_id' => Auth::user()->id, 'session_id' => session_id())); // Создаем новую запись логина вместе с session_id.
return Redirect::to('/');
}
Session::flash('error', 'Auth not excepted. '. implode(' ', array_only(Input::get(), array('email', 'password'))));
return Redirect::to('logins')->withInput(Input::except('password'));
}
バイヤーと連携するように auth.php の設定を変更しました。購入者のログインとパスワードを入力しているときに、すべてうまくいきます。Auth::attempted() の後、設定は変更されないようです。Auth オブジェクトをリロードする必要があるようです。誰か助けてくれませんか?
私がこのように書いた場合、方法を購入してください:
public function postIndex()
{
Config::set('auth.model', 'User');
Config::set('auth.table', 'users');
$test = Config::get('auth.model');
if (Auth::attempt(array_only(Input::get(), array('email', 'password')), array_only(Input::get(), array('save')))) {
Login::create(array('user_id' => Auth::user()->id, 'session_id' => session_id())); // Создаем новую запись логина вместе с session_id.
return Redirect::to('/');
}
Session::flash('error', 'Auth not excepted. '. implode(' ', array_only(Input::get(), array('email', 'password'))));
return Redirect::to('logins')->withInput(Input::except('password'));
}
すべてがうまく機能します。