2017-02-12 3 views
0

私はログイン、登録、またはパスワードフォームを忘れましたPOSTデータを取得できません。これは私のformタグですが:認証後にPOSTデータを取得するにはどうすればよいですか?

<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}"> 

それはので、私はそれが現在のページに戻ってリダイレクトされます推測している/loginで終わるものではありません。とにかくこのデータを取得するにはどうすればよいですか?

私の目標は、人が登録/ログイン/パスワードフォームを使用したかどうかを知ることです。

マイコントローラ:

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use App\Blog; 
use App\Account; 
use Illuminate\Foundation\Auth; 
use Illuminate\Support\Facades\Input; 

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

    /** 
    * Show the application dashboard. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index(Request $request) 
    { 
     $blogItems = Blog::all(); 
     $onlinePlayers = Account::getOnlinePlayers()->count(); 
     $onlineStaff = Account::getOnlineStaff()->count(); 
     $input = Request('username'); 
     return Auth::routes(); 
    } 
} 

ログインフォーム:

   <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}"> 
        {{ csrf_field() }} 

        <div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}"> 
         <label for="username" class="col-md-4 control-label">Username</label> 

         <div class="col-md-6"> 
          <input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required autofocus> 

          @if ($errors->has('username')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('username') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> 
         <label for="password" class="col-md-4 control-label">Password</label> 

         <div class="col-md-6"> 
          <input id="password" type="password" class="form-control" name="password" required> 

          @if ($errors->has('password')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('password') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group"> 
         <div class="col-md-6 col-md-offset-4"> 
          <div class="checkbox"> 
           <label> 
            <input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me 
           </label> 
          </div> 
         </div> 
        </div> 

        <div class="form-group"> 
         <div class="col-md-8 col-md-offset-4"> 
          <button type="submit" class="btn btn-primary"> 
           Login 
          </button> 

          <a class="btn btn-link" href="{{ url('/password/reset') }}"> 
           Forgot Your Password? 
          </a> 
         </div> 
        </div> 
       </form> 

マイルート:

<?php 

/* 
|-------------------------------------------------------------------------- 
| Web Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register web routes for your application. These 
| routes are loaded by the RouteServiceProvider within a group which 
| contains the "web" middleware group. Now create something great! 
| 
*/ 

//Auth 
Auth::routes(); 

//Homepage 
Route::get('/', '[email protected]'); 
Route::get('/home', '[email protected]'); 
Route::get('/logout', '\App\Http\Controllers\Auth\[email protected]'); 

EDIT(彼らは別のモーダルで同じページ上のすべてです)

LoginController:

<?php 

namespace App\Http\Controllers\Auth; 

use \Auth; 
use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\AuthenticatesUsers; 
use Illuminate\Auth\Authenticatable; 
use Illuminate\Http\Request; 
use App\Account; 

class LoginController extends Controller 
{ 
    /* 
    |-------------------------------------------------------------------------- 
    | Login Controller 
    |-------------------------------------------------------------------------- 
    | 
    | This controller handles authenticating users for the application and 
    | redirecting them to your home screen. The controller uses a trait 
    | to conveniently provide its functionality to your applications. 
    | 
    */ 

    use AuthenticatesUsers; 

    /** 
    * Where to redirect users after login. 
    * 
    * @var string 
    */ 
    protected $redirectTo = '/home'; 

    /** 
    * Create a new controller instance. 
    * 
    * @return void 
    */ 
    public function __construct() 
    { 
     $this->middleware('guest', ['except' => 'logout']); 
    } 

    /** 
    * Override the username method used to validate login 
    * 
    * @return string 
    */ 
    public function username() 
    { 
     return 'username'; 
    } 
} 
+0

あなたのルートファイルである何'/ login'ルートのために? – Jerodev

+0

私は自分のコントローラに 'Auth :: routes();'を定義しなければなりません。 –

+0

私はあなたの問題が何であるかを理解するために少しだけコードを見る必要があると思う。 – dargue3

答えて

1

間違いなく可能です。あなたのHTMLがある場合

:あなたは、次のコマンドを使ってログインデータを取得することができます

<input type="text" name="username"/><br/> 
<input type="password" name="password"/><br/> 

コントローラのアクション内で、次のコマンドを使用します。

string username = Request["username"]; 
string password = Request["password"]; 
+0

これはうまくいかない。それは定数が存在しないと言います。代わりに '$ request'を使うと値は空です。リクエスト( 'username')もそうです –

関連する問題