php - Laravel 8 : cant change laravel auth redirection
Get the solution ↓↓↓
I have installed adminlte https://github.com/jeroennoten/Laravel-AdminLTE/wiki , and previously set the default url after logging into '/ beranda'. But when I try to get it back to the original url which is '/ home', it doesn't work. Url remains pointing to 'beranda'. how to change it?
I've tried this:
composer dump-autoload
php artisan cache:clear
php artisan config:cache
php artisan route:cache
config/adminlte.php
'use_route_url' => false,
'dashboard_url' => 'home',
'logout_url' => 'logout',
'login_url' => 'login',
'register_url' => 'register',
'password_reset_url' => 'password/reset',
'password_email_url' => 'password/email',
'profile_url' => false,
Auth/LoginController.php
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
Providers/RouteServiceProvider.php
public const HOME = '/home';
Providers/AuthServiceProvider.php
public function boot()
{
$this->registerPolicies();
Gate::define('isAdmin', function ($user) {
return $user->role == 'admin';
});
Gate::define('isMember', function ($user) {
return $user->role == 'member';
});
}
Routes
Auth::routes();
Route::get('/', [HomeController::class, 'index']);
Route::get('/beranda', [BerandaController::class, 'index'])
->middleware('can:isMember')
->name('beranda');
Route::get('/booking', [BookingController::class, 'index'])
->middleware('can:isMember')
->name('booking');
Route::get('/invoice', [InvoiceController::class, 'index'])
->middleware('can:isMember')
->name('invoice');
Route::get('/trip', [TripController::class, 'index'])
->middleware('can:isMember')
->name('trip');
Route::get('/setting', [SettingController::class, 'index']);
Route::get('/home', function () {
return view('home');
})->name('home')->middleware('auth');
Route::get('/admin/beranda', [AdminBerandaController::class, 'index'])
->middleware('can:isAdmin')
->name('adminBeranda');
Answer
Solution:
Sorry this is my mistake, on navbar menu login, i put link '/beranda' instead of 'login'
so when i click the link, beranda will check for login, event admin's role will redirect to beranda after login.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: a non-numeric value encountered in
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

