admin管理员组文章数量:1400202
I am using built-in authentication for login and registration with the following command:
php artisan ui bootstrap --auth
Now, the problem is that I am already logged into my site. When I open another tab and visit the login URL:
https://localhost/v12-world/login
It redirects me to:
https://localhost/v12-world/home
But I want to be redirected to:
https://localhost/v12-world/admin/cities
I have already added this redirection in the LoginController.
Still having issue...
I modified the LoginController
to change the redirection after login. However, even after making these changes, when I visit the login URL while already logged in, it still redirects to /home
instead of /admin/cities
.
I expected the system to detect that I am already logged in and directly redirect me to /admin/cities
instead of /home
.
LoginController :
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
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 = '/admin/cities';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->middleware('auth')->only('logout');
}
}
I am using built-in authentication for login and registration with the following command:
php artisan ui bootstrap --auth
Now, the problem is that I am already logged into my site. When I open another tab and visit the login URL:
https://localhost/v12-world/login
It redirects me to:
https://localhost/v12-world/home
But I want to be redirected to:
https://localhost/v12-world/admin/cities
I have already added this redirection in the LoginController.
Still having issue...
I modified the LoginController
to change the redirection after login. However, even after making these changes, when I visit the login URL while already logged in, it still redirects to /home
instead of /admin/cities
.
I expected the system to detect that I am already logged in and directly redirect me to /admin/cities
instead of /home
.
LoginController :
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
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 = '/admin/cities';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->middleware('auth')->only('logout');
}
}
Share
Improve this question
edited Mar 27 at 6:03
Urmish Solanki
asked Mar 26 at 13:23
Urmish Solanki Urmish Solanki
235 bronze badges
2
- It is quite hard to help you without seeing the code. Do you have this code in your login controller? protected $redirectTo = '/home'; – Raffaele Bertani Commented Mar 26 at 20:41
- @RaffaeleBertani , Hello Please Check I added My Login Controller code !! – Urmish Solanki Commented Mar 27 at 6:04
1 Answer
Reset to default 0For laravel 12, you can add the following in bootstrap/app.php
:
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->redirectUsersTo('/admin/cities'); // add this
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
You can check from this page here.
本文标签: phpLaravel V12 authentication redirects to home instead of custom URLStack Overflow
版权声明:本文标题:php - Laravel V12 authentication redirects to home instead of custom URL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744141404a2592637.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论