誰かが私にLaravel
5.2認証を変更するのを手伝ってもらえますか?私は、デフォルトのデータベース移行を適切に調整する方法と、認証を設定する方法を理解することはできません。私はすでにデータベースを移行し、認証のビューを生成して認証をテストしました。そして、私がする必要があるのは、password_resets
とusers
テーブルの両方の名前を変更することと、両方のテーブルフィールドで同じことを変更することで、変更をロールバックしようとしました。 password_resets
とusers
のすべてのフィールドに接頭辞を追加する必要があります。私はそれをやり遂げる方法を研究し、それをテストしました。しかし、私はテーブル構造を変更したので、フォームを送信するたびに常にエラーが発生します。私はデータベースを調整した後、どこで何を修正すべきかを理解する必要があります。誰かがこれで私を導くことができますか?とても感謝しております。私は非常にLaravel
に新しく、私は本当にフレームワークを学びたい。Laravel 5.2認証を変更してください
ここに私の進歩があります:
私はテーブルの名前を変更しました。私は私がusr_
でフィールドにプレフィックスを追加emr_users
テーブルのフィールドに対して、両方users
とpassword_resets
にプレフィックスemr_
を追加し、emr_password_resets
のために私はps_
を追加しました。
usersテーブル:2014_10_12_000000_create_users_table
//some codes
Schema::create('emr_users', function (Blueprint $table) {
$table->increments('usr_id');
$table->string('usr_name');
$table->string('usr_email')->unique();
$table->string('usr_password');
$table->rememberToken();
$table->timestamps();
});
//some codes
password_resetsテーブル:2014_10_12_100000_create_password_resets_table
//some codes
Schema::create('emr_password_resets', function (Blueprint $table) {
$table->string('ps_email')->index();
$table->string('ps_token')->index();
$table->timestamp('ps_created_at');
});
//some codes
php artisan migrate
を使用してデータベースを移行し、すべてが正常に見えるが、私は、ログインフォームをテストし、それを送信したとき、私は取得php artisan serve
を実行した後次のエラー:
2/2 QueryException in Connection.php line 673:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'emr.users' doesn't exist (SQL: select * from `users` where `email` = [email protected] limit 1)
...
と
1/2 PDOException in Connection.php line 333:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'emr.users' doesn't exist
...
私は/config/auth.php
ファイルを編集することで上記のエラーを解決しました。だから、エラーが消えると認識し
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model/table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'users' => [ /* line 73 */
'driver' => 'database',
'table' => 'emr_users', /* line 75 */
], /* line 76 */
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
],
];
:デフォルトでは、コードのブロックは、私は、コードのブロックのコメントを解除73 76にラインでこのファイルでコメントアウトとにつながるライン75に'table' => 'emr_users'
に'table' => 'users'
を変更でテーブルemr_users
。
2/2 QueryException in Connection.php line 673:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select * from `emr_users` where `email` = [email protected] limit 1)
...
と
1/2 PDOException in Connection.php line 333:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause'
email
フィールドだusr_email
フィールドに変更された理由を示して、上記のエラー:しかし、私は、ログインフォームから再提出しようとすると、別のエラーを生成します。
は、ここで私はきちんとどこで、何を修正するために識別するために、Laravel 5.2の認証設計や構造と一緒にこれらのテーブルとフィールドを構成する方法を理解したいAuthController.php
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
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;
/**
* Where to redirect users after login/registration.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct() {
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* 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, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
/**
* 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']),
]);
}
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*
* Overrides AuthenticateUsers.php postLogin function
*/
public function postLogin(Request $request) {
$attempt_request = [
'usr_email' => $request->email,
'usr_password' => $request->password
];
if (Auth::attempt($attempt_request)) {
// Authentication passed...
return redirect()->intended('dashboard');
}
}
}
の内容です。
助けてください。ありがとう
あなたが試したこととあなたが持っていたエラーを共有しますか? – Abbasi
ご回答いただきありがとうございます。私は自分の投稿を親切に編集し直しました。 – emurmotol