2016-02-01 9 views
7

php artisan make:auth चलाने के बाद सभी आवश्यक मार्ग route.php फ़ाइल में हैं, लेकिन क्या एक को हटाना संभव है (मैं रजिस्टर मार्ग को हटाना चाहता हूं)?लार्वा प्रमाणीकरण से मार्ग को बाहर निकालें

वर्तमान में मैं

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

मुझे पता है कि Route::auth() सभी मार्गों को जोड़ने के लिए एक शॉर्टकट है। क्या मुझे शॉर्टकट का उपयोग करने के बजाय स्वयं मार्गों को निर्दिष्ट करना चाहिए?

उत्तर

7

दुर्भाग्यवश आप Route::auth() के वर्तमान कार्यान्वयन के साथ रजिस्टर को बाहर नहीं कर सकते हैं।

आप मैन्युअल रूप से इतना

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

मुझे लगता है कि यह एक बहुत ही आम बात करने के लिए यह अच्छा होगा यदि वहाँ रजिस्टर के बिना कहने के लिए auth विधि के लिए एक पैरामीटर था होगा चाहते करने के लिए है सभी मार्गों को निर्दिष्ट करने के लिए होता है शायद आप परियोजना के लिए पुल अनुरोध जमा कर सकते हैं।

1

मार्क डेविडसन ने कहा, यह बॉक्स से बाहर संभव नहीं है। लेकिन इस तरह मैंने संभाला है।

अब यह अधिक हो सकता है, लेकिन मैं आवश्यकतानुसार एक सरणी के साथ गुजरता हूं। यदि कोई पैरामीटर पारित नहीं होता है, तो डिफ़ॉल्ट मार्ग बनाए जाते हैं।

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

अपने मामले के लिए, आप शायद सिर्फ एक boolean एक array के बजाय पैरामीटर के रूप में पारित कर सकते हैं। यदि बूलियन true है तो register मार्ग लोड न करें, अन्यथा सबकुछ लोड करें।

उम्मीद है कि यह मदद करता है।

2

मैं सिर्फ YOLO और इस

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

यह करने के लिए RegisterController.php

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

में बदल रजिस्टर पेज की आवश्यकता में loged जा करने के लिए यह तक पहुँचने के लिए बनाता है।

यह एक हैक है। लेकिन यह एक अच्छा हैक है।

संपादित करें: और सिर्फ अपने बोने की मशीन में जोड़ने के जीवन को आसान बनाने के लिए:

$u1= new App\User; 
    $u1->name = 'Your name'; 
    $u1->email = '[email protected]'; 
    $u1->password = bcrypt('yourPassword'); 
    $u1->save(); 
संबंधित मुद्दे