Search code examples
phplaravellaravel-bladelaravel-routing

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.


Solution

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