2016-02-01 17 views
7

Sau khi chạy php artisan make:auth tất cả các tuyến đường bắt buộc nằm trong tệp route.php, nhưng có thể xóa một tuyến đường (tôi muốn xóa tuyến đăng ký) không?Loại trừ tuyến đường khỏi xác thực Laravel

Hiện nay tôi có

Route::group(['middleware' => 'web'], function() { 
    Route::auth(); 
}); 

Tôi biết rằng Route::auth() là một phím tắt để thêm tất cả các tuyến đường. Tôi có nên chỉ định tuyến đường thay vì sử dụng lối tắt không?

Trả lời

7

Rất tiếc, bạn không thể loại trừ đăng ký với triển khai hiện tại là Route::auth().

Bạn sẽ phải chỉ định tất cả các tuyến đường bằng tay để

// Authentication Routes... 
$this->get('login', 'Auth\[email protected]'); 
$this->post('login', 'Auth\[email protected]'); 
$this->get('logout', '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]'); 

Tôi nghĩ rằng đây là một điều khá phổ biến để muốn làm điều đó sẽ được tốt đẹp nếu có một tham số cho auth phương pháp để nói mà không đăng có thể bạn có thể gửi yêu cầu kéo tới dự án.

1

Như Mark Davidson đã nói, không thể ra khỏi hộp. Nhưng đây là cách tôi đã xử lý.

Bây giờ nó có thể là quá mức cần thiết, nhưng tôi chuyển một loạt những gì cần thiết. Nếu không có tham số nào được truyền, thì các tuyến mặc định sẽ được tạo.

// Include the authentication and password routes 
Route::auth(['authentication', 'password']); 
/** 
* Register the typical authentication routes for an application. 
* 
* @param array $options 
* @return void 
*/ 
public function auth(array $options = []) 
{ 
    if ($options) { 
     // Authentication Routes... 
     if (in_array('authentication', $options)) { 
      $this->get('login', 'Auth\[email protected]'); 
      $this->post('login', 'Auth\[email protected]'); 
      $this->get('logout', 'Auth\[email protected]'); 
     } 

     // Registration Routes... 
     if (in_array('registration', $options)) { 
      $this->get('register', 'Auth\[email protected]'); 
      $this->post('register', 'Auth\[email protected]'); 
     } 

     // Password Reset Routes... 
     if (in_array('password', $options)) { 
      $this->get('password/reset/{token?}', 'Auth\[email protected]'); 
      $this->post('password/email', 'Auth\[email protected]'); 
      $this->post('password/reset', 'Auth\[email protected]'); 
     } 
    } else { 
     // 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]'); 
    } 
} 

Đối với trường hợp của bạn, bạn có thể có lẽ chỉ vượt qua một boolean như tham số thay vì một array. Nếu boolean là true thì không tải các tuyến đường register, nếu không tải mọi thứ.

Hy vọng điều đó sẽ hữu ích.

2

Tôi chỉ YOLO và thay đổi này trong RegisterController.php

public function __construct() 
{ 
    $this->middleware('guest'); 
} 

này

public function __construct() 
{ 
    $this->middleware('auth'); 
} 

Điều này làm cho các trang đăng ký yêu cầu bạn phải được loged trong để đạt được nó.

Đó là một hack. Nhưng nó là một hack tốt.

EDIT: và chỉ cần thêm video này vào seeder của bạn để làm cho cuộc sống dễ dàng hơn:

$u1= new App\User; 
    $u1->name = 'Your name'; 
    $u1->email = '[email protected]'; 
    $u1->password = bcrypt('yourPassword'); 
    $u1->save(); 
Các vấn đề liên quan