2016-08-29 25 views
44

Ostatnio zaczynam używać laravel 5,3 pisać bloga, ale mam pytanie po biegu php artisan make:authlaravel 5.3 :: uwierzytelniania nowe trasy()

gdy uruchamiam to będzie generować trasy w moim web.php

jest to kod w nim:

Auth::routes(); 

Route::get('/home', '[email protected]'); 

Potem biegnę php artisan route:list uważam, że wiele działań, takich jak LoginController @ logowania ...

Ale nie znalazłem tych działań w moim App\Http\Controllers\Auth, gdzie są te?

A także co oznacza Auth::routes(), nie mogę znaleźć tras o Auth.

muszę komuś pomóc, dziękuję Ci odpowiedzieć na moje pytanie

Odpowiedz

84

uwierzytelniania :: tras() jest po prostu klasa pomocnika, który pomaga generować wszystkie szlaki wymaganych do uwierzytelnienia użytkownika. Zamiast tego możesz przeglądać kod tutaj: https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php.

Oto trasy

// 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]'); 
+0

Dzięki! Widzę ../Routing/Router.php i teraz wiem, jak działają trasy. Ale gdzie jest ścieżka metod Auth static()? Nadal nie mogę go znaleźć, wybacz mi, że jestem początkującym larcą ... – g1eny0ung

+1

Metoda Auth :: routes jest tutaj https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/ Auth.php i jego wywołanie funkcji routera. Proszę oznaczyć to jako odpowiedź, jeśli ci to pomogło, dziękuję. – Lee

+1

'Auth' jest * elewacja * i będzie zdefiniowany w' config/app.php' Znajdziesz klasę, która działa jako dostawca w tym pliku konfiguracyjnym. – Jason

0

klasa LoginUser wykorzystuje cechę zwaną AuthenticatesUsers

jeśli otworzysz tę cechę można zobaczyć funkcji (dotyczy to innych sterowników) Illuminate\Foundation\Auth\AuthenticatesUsers;

Oto kod cecha https://github.com/laravel/framework/blob/5.1/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php

przepraszam za zły format, im przy użyciu mojego telefonu

również Auth::routes() to po prostu wywołuje funkcję, która zwraca trasy auth to wszystko (chyba)

+0

Tak, patrzę przez Auth/dir, ale ja nie znaleźliśmy sposobu, jak App \ http \ Sterowniki \ Auth \ ResetPasswordController @ showResetForm, gdzie mogę znaleźć metody po @, ja kosztować dużo czasu, aby go znaleźć, ale teraz też go nie mogę znaleźć .. Jestem nowy w laravel .. – g1eny0ung

+1

tutaj jest pełna ścieżka 'sprzedawca \ laravel \ src \ Illuminate \ Foundation \ Auth \ ResetsPasswords', jeśli chcesz zmień to lub coś, nie zmieniaj tego, po prostu dodaj tę samą metodę do kontrolera ur, a następnie zmień go, –

+0

@Achraf Khouadja, Wygląda na to, że opanowałeś laravel. Potrzebuję twojej pomocy. Zajrzyj tutaj: http://stackoverflow.com/questions/41047583/how-to-add-dynamic-dropdown-list-column-on-laravel-5-3-registration –

31

trasy uwierzytelniania dla laravel 5,3 zamiast Auth :: trasach(). Mam nadzieję, że to pomaga ...

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]']); 
}); 

Więc jeśli zmienić niektóre nazwy tych dróg, należy pamiętać również zmienić w widokach Działania postów!

2

funkcja kolejność połączeń:

  1. (Auth) Illuminate \ Support \ elewacje \ Auth @ trasy (https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Auth.php)
  2. (APP) Illuminate \ Fundacja \ Application @ auth
  3. (Route) Illuminate \ Routing \ Router

to droga tak:

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]set'); 
} 
+0

https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php#L298 –

7

Dla 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]'); 
Powiązane problemy