2017-02-12 53 views
0

Wether我提交登錄,註冊或忘記密碼錶單我無法檢索POST數據。雖然這是我的表單標籤:如何在Auth後檢索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]'); 

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

什麼是你的路由文件爲'/登錄'路線? – 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'而不是值爲空時。請求('用戶名')也是如此 –