kash101
kash101

Reputation: 269

link to specific anchor on a page with Laravel

How does one go about linking to a specific id in a view with Laravel?

My controller:

public function services() {
 return View::make('services.custom_paint', array('pageTitle' => 'Custom Paint'))->with('default_title', $this->default_title);
}

My route:

Route::get('/custom_paint',  'PagesController@services');

I have tried to add #id to the route, to the controller, and even to the view's URL::to. Nothing seems to work.

I assumed that simply adding the id on to the URI would do the trick, but clearly I am missing something.

Upvotes: 3

Views: 19509

Answers (3)

Elshan
Elshan

Reputation: 7683

If you pass id to controller as parameter and need to point to correct result with #id

 <a href="{{ route('custom_paint',['id'=>'$id_value','#id']) }}">Try</a>

I assume above will render as http://localhost/custom_paint/id=123#id

Or Just point to ID:

<a href="{{ route('custom_paint',['#id']) }}">Try</a>

I assume above will render as http://localhost/custom_paint/#id

Upvotes: 2

Bikal Basnet
Bikal Basnet

Reputation: 1739

Simply use

<a href="{{ route('custom_paint') }}">LINK</a>

if parameter is needed use it like this

<a href="{{ route('custom_paint', 'param1') }}">LINK</a>

route

Upvotes: -1

lieroes
lieroes

Reputation: 694

// Controller
Route::get('/custom_paint', array('as' => 'custom_paint', 'uses' => 'PagesController@services'));

// View
<a href="{{ URL::route('custom_paint') }}#id">LINK</a>

Try this code ;) hope it works..

Upvotes: 11

Related Questions