Laravel Livewire Passing variable data from one component to another using redirect

Viewed 1697

I am trying to make an update process using two livewire controller. I want to pass the id of the selected page and pass that data to another livewire controller.

I've tried to use: return redirect()->route('system-pages/update-system-page', ['pages_id' => $this->modelId]); to pass the data to the url in which the $this->modelId is the id of the page. The current URL right now whenever I select a page is http://127.0.0.1:8000/system-pages/update-system-page?pages_id=7.

I'm getting the id by converting the url into string and selecting the final character: $this->pageData = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";.

Is there any better way to get the id from another component and pass that data to another livewire component? Thank you.

1 Answers

instead of using query string, try to put the id in path

so it'll be http://127.0.0.1:8000/system-pages/update-system-page/7

to do that, in your route, just add a variable : Route::get('system-pages/update-system-page/{pages_id}')

and then inside your livewire controller, get the id using mount method

public function mount($pages_id){

}

the redirect code still same as yours.

source : https://laravel-livewire.com/docs/2.x/rendering-components#route-params

Related