0

I use "return redirect()->route()" to routing but I have a tab named "#tab4" but cannot add this to url with redirect()->route. I want to show the same tab after submit but cannot set the url.when I use redirect()->back(), cannot see success message and page does not resresh. How to do that in laravel?

sessionsuccess("asdfghj.");

return  redirect()->route('manage.customers.detail', ['account' => $this->account->id]);

the url I want: http://localhost:8000/manage/customers/detail/9#tab4

wertyu
  • 93
  • 1
  • 3
  • 17

4 Answers4

0

web.php on route

Route::view('/#detail', 'manage.customers.detail/{account_id}')->name('detail');

on controller

return  redirect()->route("detail")->with("account_id"=>$this->account_id);

Try this.I believe working this

  • So you will create a different route for every tab? That might work, but it's not a good solution. – Gert B. Dec 28 '21 at 08:03
  • you can this foreach with use prefix but dont need this manage.customers.detail just changing parameters value route is same but ıf you want use prefix route patch foreach – Emrah Çalışkan Dec 28 '21 at 08:08
  • Or you can keep it simple and dynamic, and chain the tab to the outputted route. So you don't need to edit the route file for every new tab. Adding the tab links in the routes is not a good solution at all. Your route file will be a lot larger, it's harder to maintain. – Gert B. Dec 28 '21 at 08:14
  • I have no idea about this subject. Can you share an example? – Emrah Çalışkan Dec 28 '21 at 08:17
0

Try to use :

return redirect()->to(route('manage.customers.detail', ['account' => $this->account->id]).'#tab4');
0

Store your current tab inside a session variable. after loading view, sessions can be used and retrieve your last tab

Mohsen Amani
  • 82
  • 1
  • 8
0

You need to save your tab as a flash so whenever you submitted the tab can be active in your controller method

Session::flash('tab', 'table_name');

and in your view you can work like this

Session::has('tab')? 'active' :''

for more details https://laravel.com/docs/5.0/session#flash-data

second way you can work link

return redirect()->route('manage.customers.detail', ['account' => $this->account->id, '#tab4']);

Syed Ali
  • 151
  • 1
  • 4