简体   繁体   中英

How can i change my dashboard field after Authentication? laravel-8

I can login and register with laravel-8 after login or register it takes me to the dashboard which is an automated generated page with auth in laravel -8 named dashbord.blde.php but after login I want to go to my index.blade.php page path of this page is resource/views/prducts/index.blade.php. Thanks in advance. :) here in my web.php

Route::get('/', function () {
    return view('welcome');
});

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
    return view('dashboard');
})->name('dashboard');

If you take a look at the app/Http/Controllers/Auth/LoginController.php file, for example, you would find the following code:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{

    use AuthenticatesUsers;

    protected $redirectTo = '/home';

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

You can see that a $redirectTo variable exists and has the value of /home where users are redirected after they are logged in.

In this case, you should change it to protected $redirectTo = '/dashboard';

stolen with respect from: https://www.techiediaries.com/laravel-auth-redirection-using-redirectto/

Following the contribution above, you can change the '/home' redirect to '/products/index', and in the web.php declare this route

Route::get('/products/index', function(){
    return view('products.index');
})->name('products_index');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM