2016-07-25 7 views
1

は、だから私は最近、自分自身をコマンドにしてみてくださいLaravel Authを作成し、認証の背後に登録を非表示にしますか?

php artisan make:auth 

の代わりに、認証のすべてを作成することを決定し、動作するように見えたし、私は私のアプリでの継続しました。しかし、今私は私のアプリのポイントで私は公共の面接登録ページ(私はこれを管理者だけ新しいユーザーを追加する)したくないです。ただし、コマンドは個々のルートや関数を挿入するものではなく、laravelに組み込まれたものです。だから、通常は誰もが作成したレジスタページを維持する方法を知っています....私はちょうどレジスタを取り扱うコントローラの内部

$this->middleware('auth'); 

を使用することができますが、それはそれが問題を引き起こしログインと同じコントローラであるため、 php artisan make:login wallの背後にあるauthなので、管理者だけが新しいユーザーを登録できますか?

+0

https://laravel.com/docs/5.2/middleware#assigning-middleware-to-routesとhttps://laravel.com/docs/5.2/controllers#controllerミドルウェアは必要なものすべてを持っています。 – ceejayoz

+0

私の問題は、これらのドキュメントでは、組み込みのauthコマンドの問題に対処できないということでした。私はphp artisan make:authコマンドで設定した既存ルートの編集や変更方法を知らない。たとえば、次のようなことをします。 Route :: get( 'register'、['middleware' => 'auth'、function(){ // }]); 何もしません。 – CMOS

+0

これは問題ありません。コンストラクタのゲストミドルウェアはログイン/ログアウトを処理する必要があります。あなたは私の答えを参照してルートを定義する場所から認証ミドルウェアを適用することができます。 – ClearBoth

答えて

0

最初に、ユーザー登録の現在のルートをキャンセルします。 (これを行うにはいくつかの方法があります)例:Route :: auth();あなたが適用したいルートだけを適用してください。

/** 
* Register the typical authentication routes for an application. 
* 
* @return void 
*/ 
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]'); 
} 

第二:次のようrouter.phpで定義されたAUTH()ミドルウェア認証を使用して独自のルートを作成は、元の適用:

Route::get('users/create', [ 
    'middleware' => 'auth', 
    'as' => 'users.create', 
    'uses' => 'Auth\[email protected]' 
]); 

あなたは切り抜いた方法でミドルウェアを適用することができ、よりために、このリンクを参照してください: https://laravel.com/docs/5.2/routing#route-group-middleware

0

thisに基づいて、あなたがAuthenticatesAndRegistersUsers形質を使用し、次にgetRegister and postRegisterメソッドをオーバーライドし、独自の認証コントローラを作成することができるはずと思われます。

のような何か:

<?php 

namespace App\Http\Controllers\Auth; 

use Request; 
use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; 

class AuthController extends Controller 
{ 
    use AuthenticatesAndRegistersUsers; 

    /** 
    * Create a new authentication controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('auth'); 
    } 

    /** 
    * Show the application registration form. 
    * @return Response 
    */ 
    public function getRegister() 
    { 
     // show register view 
    } 

    /** 
    * Handle a registration request for the application. 
    * @return Response 
    */ 
    public function postRegister(Request $request) 
    { 
     // register logic 
    } 

} 
関連する問題