简体   繁体   中英

Can I enter from admin to an authenticated user dashboard?

I am working in a project in laravel with livewire. I am working in the admin dashboard that has all user data in a simple table. In this table, I have been requested that when I click on user name, I have to be sent to the specified user dashboard that has been created with livewire. The problem is that users are authenticated and I cant find a way to get there.

client-list blade

                <tr class="text-gray-700">
                    <td class="border p-2" style="text-align:center; text-decoration:underline">
                    <a href= "{{URL::to('/dashboard-admin/'.$user->id)}}">{{($user->first_name) }}</a></td>
                    <td class="border p-2" style="text-align:center">{{($user->last_name) }}</td>
                    <td class="border p-2" style="text-align:center">{{($user->email) }}</td>
                    <td class="border p-2" style="text-align:center">

And web.php:

Route::get('/dashboard/{user}','\\App\\Http\\Controllers\\DashboardController@index')->name('dashboard-admin');

You can use the loginUsingId() in your controller for login into the user dashboard:

https://laravel.com/docs/8.x/authentication#authenticate-a-user-by-id

On your DashboardController :

public function index(User $user)
{
    // ...

    Auth::loginUsingId($user->id);

    // ...
}

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