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}','AppHttpControllersDashboardController@index')->name('dashboard-admin');
Advertisement
Answer
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); // ... }