link to specific anchor on a page with Laravel

[亡魂溺海] 提交于 2019-12-13 14:08:41

问题


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.


回答1:


// 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..




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/24275667/link-to-specific-anchor-on-a-page-with-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!