最近私はlaravel 5.3を使ってブログを書き始めましたが、php artisan make:auth
を実行した後に質問があります
これを実行すると、私のweb.php
にルートが生成されます。
これはその中のコードです:
Auth::routes();
Route::get('/home', '[email protected]');
それから私はphp artisan route:list
を実行します、私はLoginController @ loginのようなたくさんの行動を見つけます...
しかし、私はApp\Http\Controllers\Auth
にこれらのアクションが見つかりませんでした、これらはどこにありますか?
また、Auth::routes()
の略で、Authに関するルートが見つかりません。
私は誰か助けが必要です、私の質問に答えてくれてありがとう
Auth::routes()
は、ユーザー認証に必要なすべてのルートを生成するのを手助けする単なるヘルパークラスです。あなたはここでコードを閲覧することができます https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php 代わりに。
こちらがルートです
// Authentication Routes...
$this->get('login', 'Auth\[email protected]')->name('login');
$this->post('login', 'Auth\[email protected]');
$this->post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
$this->get('register', 'Auth\[email protected]')->name('register');
$this->post('register', 'Auth\[email protected]');
// Password Reset Routes...
$this->get('password/reset', 'Auth\[email protected]');
$this->post('password/email', 'Auth\[email protected]');
$this->get('password/reset/{token}', 'Auth\[email protected]');
$this->post('password/reset', 'Auth\[email protected]');
Auth :: routes()の代わりにLaravel 5.3の認証ルート。私はそれが役立つことを願っています...
Route::group(['middleware' => ['web']], function() {
// Login Routes...
Route::get('login', ['as' => 'login', 'uses' => 'Auth\[email protected]']);
Route::post('login', ['as' => 'login.post', 'uses' => 'Auth\[email protected]']);
Route::post('logout', ['as' => 'logout', 'uses' => 'Auth\[email protected]']);
// Registration Routes...
Route::get('register', ['as' => 'register', 'uses' => 'Auth\[email protected]']);
Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\[email protected]']);
// Password Reset Routes...
Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\[email protected]']);
Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\[email protected]']);
Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\[email protected]']);
Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\[email protected]']);
});
そのため、これらのルートの名前を変更した場合は、投稿のアクションもビューで変更することを忘れないでください。
ああ、ちょっと、これは Laravel 5.7 includes 検証ルート です。
// Authentication Routes...
Route::get('login', 'Auth\[email protected]')->name('login');
Route::post('login', 'Auth\[email protected]');
Route::post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
Route::get('register', 'Auth\[email protected]')->name('register');
Route::post('register', 'Auth\[email protected]');
// Password Reset Routes...
Route::get('password/reset', 'Auth\[email protected]')->name('password.request');
Route::post('password/email', 'Auth\[email protected]')->name('password.email');
Route::get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
Route::post('password/reset', 'Auth\[email protected]')->name('password.update');
// Email Verification Routes...
Route::get('email/verify', 'Auth\[email protected]')->name('verification.notice');
Route::get('email/verify/{id}', 'Auth\[email protected]')->name('verification.verify');
Route::get('email/resend', 'Auth\[email protected]esend')->name('verification.resend');
Laravel 5.5.xの場合
// Authentication Routes...
$this->get('login', 'Auth\[email protected]')->name('login');
$this->post('login', 'Auth\[email protected]');
$this->post('logout', 'Auth\[email protected]')->name('logout');
// Registration Routes...
$this->get('register', 'Auth\[email protected]')->name('register');
$this->post('register', 'Auth\[email protected]');
// Password Reset Routes...
$this->get('password/reset', 'Auth\[email protected]')->name('password.request');
$this->post('password/email', 'Auth\[email protected]')->name('password.email');
$this->get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
$this->post('password/reset', 'Auth\[email protected]');
これは Laravel 5.6 で私には役に立ちました。
ファイルweb.php
では、単に次のように置き換えます。
Auth::routes();
によって:
//Auth::routes();
// Authentication Routes...
Route::get('admin/login', 'Auth\[email protected]')->name('login');
Route::post('admin/login', 'Auth\[email protected]');
Route::post('admin/logout', 'Auth\[email protected]')->name('logout');
// Password Reset Routes...
Route::get('password/reset', 'Auth\[email protected]')->name('password.request');
Route::post('password/email', 'Auth\[email protected]')->name('password.email');
Route::get('password/reset/{token}', 'Auth\[email protected]')->name('password.reset');
Route::post('password/reset', 'Auth\[email protected]');
そして、以下の2つのファイルから Register リンクを削除します。
welcome.blade.php
layouts/app.blade.php
関数呼び出しの順序
それはこのようなルートです:
public function auth()
{
// Authentication Routes...
$this->get('login', 'Auth\[email protected]');
$this->post('login', 'Auth\[email protected]');
$this->get('logout', 'Auth\[email protected]');
// Registration Routes...
$this->get('register', 'Auth\[email protected]');
$this->post('register', 'Auth\[email protected]');
// Password Reset Routes...
$this->get('password/reset/{token?}', 'Auth\[email protected]');
$this->post('password/email', 'Auth\[email protected]');
$this->post('password/reset', 'Auth\[email protected]');
}
loginuserクラスはAuthenticatesUsers
という名前のトレイトを使います
あなたがその特性を開くと、あなたは関数を見るでしょう(これは他のコントローラーにも当てはまります)Illuminate\Foundation\Auth\AuthenticatesUsers;
ここに特性コードがあります https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/auth/AuthenticationUsers.php
私の携帯電話を使用して、悪いフォーマットをごめんね
Auth::routes()
それはそれを認証ルートを返す関数を呼び出すだけです(私は思う)
コマンドphp artisan route:list
に誰も言及していないことに驚いています。これは、登録されているすべてのアプリルートのリストを示します(登録されている場合はAuth::routes()
およびPassport::routes()
を含む)