2015-11-04 70 views
1

我在laravel 5中工作並且遇到了身份驗證登錄問題。laravel 5.1驗證嘗試登錄驗證碼

我無法登錄(使用正確的用戶和密碼),並重新導向到「登錄」頁面,而不是我想要的頁面。

我在phpmyadmin中的表被稱爲「用戶」,所以使用Auth是正確的。

它爲什麼不起作用?

<?php namespace App\Http\Controllers; 

use Auth; 

// product é a pasta e o index é a pagina 
class BackendControlador extends Controller { 

    public function index() { 

    $email = 'email'; 
    $password = 'password'; 

    if (Auth::attempt(['email' => $email, 'password' => $password, 'acesso' => 1])) { 
      return redirect()->intended('backend/dashboard.index'); 
     } elseif (Auth::attempt(['email'=> $email, 'password' => $password, 'acesso' => 0])) { 
      return redirect()->intended('welcome'); 
     } else { 
      return view('auth/login'); 
     } 
    } 

    public function portfolio() { 
     return view('backend/portfolio.index'); 
    }  
} 

我的路線代碼:

Route::get('/', function() { 
    return view('welcome'); 
}); 

Route::get('backend','[email protected]'); 

Route::get('backend/portfolio','[email protected]'); 

// Authentication routes... 
Route::get('auth/login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 

// Authentication routes... 
Route::get('auth/logout', 'Auth\[email protected]'); 

// Registration routes... 
Route::get('auth/register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 
+0

請張貼您的routes.php – davejal

+0

你能標記這個問題的答案? – davejal

回答

2

的問題是

  1. 不採取你發送的變量的代碼行,那麼你只會得到如果登錄您的用戶名等於電子郵件和密碼等於數據庫中的密碼。

    $email = 'email'; 
    $password = 'password'; 
    

它更改爲類似

$email = Request::input('email'), 
    $pass = \Hash::make(Request::input('password')) 
  • 你將不得不使用請求

    use Illuminate\Support\Facades\Request; 
    
  • use Request; 
    
  • 正如我在評論使用bestmomo
    1. 編輯您的JSON文件建議,要求

      "bestmomo/scafold": "dev-master"

    2. 更新你的作曲家與命令

    composer update

    3.未來需要的步驟是添加的服務提供商配置/ app.php:

    Bestmomo\Scafold\ScafoldServiceProvider::class,

  • 發佈
  • php artisan vendor:publish

    +0

    當我插入用戶時繼續刷新頁面 –

    +0

    也許你可以用文本替換你的重定向用於調試目的 – davejal

    +0

    不知道你是否知道https://github.com/bestmomo/scafold容易腳手架的授權 – davejal