在我的應用程序中,我使用默認認證將我的用戶登錄到他們的儀表板。 現在我想爲支持者和管理員創建一個後端。 我用這個代碼,此刻以管理員身份登錄:laravel5.1手動認證用戶
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App;
use Artisan;
use Validator;
use Auth;
class AdminLoginController extends Controller
{
public function index()
{
return view('admin.login');
}
public function authenticate(Request $request)
{
if (Auth::attempt(['username' => $request->username, 'password' => $request->password, 'id' => 1]))
{
// Authentication passed...
dd("correct");
}
else
{
dd("login data incorrect!");
}
}
}
我怎麼能現在使用登錄後的衆所周知的重定向。 在我AuthController我使用的用戶我用這個代碼:
/**
* Where to redirect users after login/registration.
*
* @var string
*/
protected $redirectTo = '/dashboard';
protected $redirectAfterLogout = 'auth/login';
protected $redirectPath = '/dashboard';
1)我怎麼能在我上面的代碼中使用此?我想重新定向管理員登錄到應用程序像用戶使用此laravel功能指定的網址。
2.)在if語句中檢查更多「id」的最佳方法是什麼?因爲會有多個管理員。
請解釋一下,你能否成功地匹配用戶信息?第二,爲什麼你不使用laravel的基於角色的包,例如:'https:// github.com/Zizaco/entrust' 3rd,而不是通過'id'將用戶表中的'user_type'字段放在用戶表中。並檢查登錄 – Qazi