Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anonymouse703's avatar

How can I redirect/go to another component with specific id?

Hello guys, I have a list of user and If I select that specific user I want to go that user profile (which another component). I don't have ideas on routing of livewire.

0 likes
15 replies
frankielee's avatar

I select that specific user

How? using select tag or there is a view button

<a href="{{route("users.show",["id"=>$user->id])}}">View </a>


anonymouse703's avatar

by button

<button wire:click="showUser({{ $user->id }})" class="btn btn-info delete-header m-1 btn-sm"  title="Show User"><i class="fas fa-eye" small></i></button>

But livewire has different routing

I tried this

public function showUser($id){
        $user = User::findOrFail($id);
        return redirect()->to('/userProfile');

    }
frankielee's avatar

Can you show your route also?

So what is not working there? the page does not redirect?

anonymouse703's avatar

this is how I route in livewire

Route::get('/showProfile', UserInvestmentTable::class)->name('showProfile');

SilenceBringer's avatar

@anonymouse703 you do not need to call redirect from server, call it in blade. Replace button with a

<a href="/userProfile/{{ $user->id }}" class="btn btn-info delete-header m-1 btn-sm"  title="Show User"><i class="fas fa-eye" small></i></a>

assuming you have route like

Route::get('/userProfile/{user}', ...
anonymouse703's avatar

Hi sir this the scenario, I have a list of users and If I clicked show user I will fetch the specific id as this

<button wire:click="showUser({{ $user->id }})" class="btn btn-info delete-header m-1 btn-sm"  title="Show User"><i class="fas fa-eye" small></i></button>

and this is the function of that in my user component

 public function showUser($id){
        // dd($id);
        return redirect()->to('/user-profile');
    }

Now that user-profile is another component where I want to display my data of that specific user.

I tried to put a listener but still not working or null

UserProfile component

public $user_id;

    public $listeners = ['user_id'];

    public function user_id($id){
        $this->user_id = $id;
    }

public function render()
    {
        // $user_id = User::where('id',$id)->get(); // I want to show the data based on the Id.
        return view('livewire.user-investment-table');
    }

in my user component

public function showUser($id){
        // dd($id);
        $this->emit('user_id',$id);
        return redirect()->to('/user-profile');
    }
SilenceBringer's avatar

@anonymouse703 did you read my previous comment?

return redirect()->to('/user-profile');

you redirected to another component - great. But how this component should know which one user you want to see? First one? Last one? WHich one?

Here router parameters are coming https://laravel.com/docs/8.x/routing#route-parameters

you should specify which one user you want to see

See the difference:

  1. /user-profile - show user profile. But I have no idea which one
  2. /user-profile/1 - ok, I see. You want to see the profile of user with the id of 1. I can do it

Read the docs

anonymouse703's avatar

I know about that router parameters but in livewire is different... Where I stuck is here..

Route::get('/user-profile}', UserInvestmentTable::class)->name('user-profile');
public function render()
    {
        return view('livewire.user-investment-table');
    }
SilenceBringer's avatar

@anonymouse703 Where you stuck is laravel basics. You got an answer about 1 hour ago, but still try to tell us that it don't. How many people should say you that you are wrong?

orlando870's avatar

@anonymouse703 intead of redirecting why dont try to call a method from another component and wait for the response by sending the parameter use this example

you can use this->redirect in livewire to redirect from your component in App\Http\Livewire\Component

use this add these lines changing it based on your case

    $component = app(ComponenetTarget::class);
    $component->classTarget($this->value1, $this->value2);
    $this->redirect($component->redirectTo); // assuming that you have the ridirect on the Target Component and here you can just access the parameter correspondent
Snapey's avatar

learn the basics

Livewire is no different

prospero's avatar
prospero
Best Answer
Level 3

just do this. web.php

Route::get('/user-profile/{user}', UserInvestmentTable::class)->name('user-profile');

in the blade

<button wire:click="showUser({{ $user->id }})" class="btn btn-info delete-header m-1 btn-sm"  title="Show User"><i class="fas fa-eye" small></i></button>

in the action component

public function showUser($id){
        return redirect()->route('user-profile',['user' => $id]);
}

and in the redirected component

public User $user;

    // or
public $user;
public function mount(User $user)
{
    $this->user = $user;
}

Please or to participate in this conversation.