1

I want to create a laravel route that links to a named anchor in a page. Could someone help with how to achieve that. Example: return Redirect::route('admin.articles.edit#somelink', $article->id);

In this case the route is in a controller which is redirecting back to the pages' comments section

user3449007
  • 37
  • 1
  • 8
  • 1
    possible duplicate of [link to specific anchor on a page with Laravel](http://stackoverflow.com/questions/24275667/link-to-specific-anchor-on-a-page-with-laravel) – Marcel Burkhard Aug 24 '15 at 10:34
  • which Laravel version are you using? Are you trying to put that in a Controller as a return of a method, in a View as a link or in the routes.php file as a new route? – Juan Girini Aug 24 '15 at 10:38
  • I will appreciate all possible scenarios as i use them a lot in my applications. I'm using version 5.1 – user3449007 Aug 24 '15 at 11:00
  • Use the answer provided from the duplicated link, and create a [macro](http://laravelcollective.com/docs/5.0/html#custom-macros) for this kind of links to make your life easier. – Avalanche Aug 24 '15 at 11:51

1 Answers1

0

I was looking for this and stumbled upon this older question.

The "possible duplicate" has an answer for the case where the link is created in a view (i.e. in html). It may not be immediately clear that this can also be used in returning a redirect route from a controller, as OP seemed to require (some years ago :).

At least in Laravel 5.5, it is possible to use this in the redirect()->to() function, e.g.:

return redirect()->to(
    route('admin.articles.edit', [$article->id]) . "#somelink"
);

Based on this answer.

Marten Koetsier
  • 3,389
  • 2
  • 25
  • 36