2015-11-04 73 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