Home > OS >  Can I enter from admin to an authenticated user dashboard?
Can I enter from admin to an authenticated user dashboard?

Time:10-16

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 hljs-number">2" style="text-align:center">{{($user->last_name) }}</td>
                    <td hljs-number">2" style="text-align:center">{{($user->email) }}</td>
                    <td hljs-number">2" style="text-align:center">

And web.php:

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

CodePudding user response:

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);

    // ...
}
  • Related