Search code examples
phplaravel-5laravel-5.3http-redirect

On redirecting to a View, slide it to the specific part of the page using #id - Laravel 5.3


I have a route which redirects to a controller which tells view to show. But how can I go to a particular part of the page. Let me Explain:

I am using fullpage.js library to create a page breakpoints. for example: /home#firstPage , /home#secondPage and so on. When I am redirected to /home I would like to go to a particular section of the page. All I need is a way to enter #3rdPage in url.

Where and How do I put this to see it action?

my Routes

Route::get('/home_done', ['as' => 'home_done','uses' => 'HomeController@home']);

my Controller

public function home()
{
    return view('home_done');
}

I would like to do something like:

    return view('home_done#3rdPage');

Solution

  • You should setup a new function and route to redirect the users to correct page after executing your logic:

    public function home()
    {
        return view('home_done');
    }
    
    public function step_3()
    {
        // do something and redirect
        return redirect('home_done#3rdPage');
    }
    

    Using view don't work since you are loading a file, not the page.