问题
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