私はLaravel 5.2を使用しています。そして私は質問をしたい。すでにログインしているときにlaravelのリダイレクトログインフォームを変更するにはどうすればよいですか?私はPHP職人make:authからauthを使用しています。ここで私が何を意味するかです:Laravel Authすでにログインしているときにログインフォームをリダイレクトする
- 私はすでにログインしてローカルホストにリダイレクト:8000/adminに
- その後、私は再びlocalhostのオープン:8000 /ログインを。それは "/"またはlocalhostにリダイレクトされます:8000/
- 私の質問はどのように "/ admin"に "/"を変更するのですか?だから私はすでにログインしていて、localhost:8000/loginを開くときに、 "/"にリダイレクトしたいのですが/ localhost:8000/admin
私はそれをAuthControllerので、ここで私のAuthControllerです:私はルートが何であるか検索するとき::
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login/registration.
*
* @var string
*/
// protected $redirectPath = '/admin';
protected $redirectTo = '/admin';
protected $redirectAfterLogout = '/login';
/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
AUTH()私はこれを見つけた:
$this->get('login', 'Auth\[email protected]');
$this->post('login', 'Auth\[email protected]');
$this->get('logout', 'Auth\[email protected]');
// Registration Routes...
$this->get('register', 'Auth\[email protected]');
$this->post('register', 'Auth\[email protected]');
// Password Reset Routes...
$this->get('password/reset/{token?}', 'Auth\[email protected]');
$this->post('password/email', 'Auth\[email protected]');
$this->post('password/reset', 'Auth\[email protected]');
だから私は問題は '認証\ AuthController @ showLoginForm' にあると思います。 AuthControllerで私が見つかりません
私はこの機能で何かしたいのですか?私はすでにログインしていた場合のようなその表情は、ログインを行う他/管理者にリダイレクト(または/ログインにリダイレクト)
とここに私のルートである:ご返信用
Route::get('/', function() {
return view('welcome');
});
//admin
Route::get('admin', function() {
return view('admin.index');
});
//login
Route::auth();
Route::get('/home', '[email protected]');
おかげで。
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/admin');
}
return $next($request);
}
それとも、特にそのためのミドルウェアを持っている可能性がありますので、のようなApp\Http\Middleware\RedirectIfAuthenticated
ミドルウェアを編集する
おかげで非常に多く!私はミドルウェアでそれをやることができないことを知っています..私はlaravelの初心者ですので、私はそれについて知っていません..ありがとう!あなたは私を大いに助けます! –
歓迎ですが、[documentation](https://laravel.com/docs/5.2/authentication)をご覧ください。 –