1

I'm using Laravel 5.0 and paginate along with the render() function in my view. Rather than go back to the top of the screen after I select the next page I want it to jump to #msgs. Here is some of my code:

<h1 class="centered" id="msgs">Announcements</h1>
    @foreach($messages->getCollection()->all() as $message)
        <div class="row">
            <div class="row">
                <div class="col-sm-9">
                    <h3>{{$message->title}}</h3>
                </div>
                <div class="col-sm-3">
                    <h4>From: {{$message->author_name}}</h4>
                </div>
            </div>
            <div class="row">
                <p>{{$message->text}}</p>
            </div>
        </div>
        <hr class="featurette-divider">
    @endforeach
    <div class="centered">
        {!! $messages->render() !!}
    </div>

I'm still getting a grasp on the flow of things in laravel so I'm not really sure what to do. I tried to use append->('#msgs') but realized that its appending an array in the parameters, not appending a path to the url. I there a simple way to achieve this without overriding anything?

John
  • 2,820
  • 3
  • 30
  • 50
  • Here's and update to the question. I'm not positive if I'm heading in the right direction now. So I've added `{!! $messages->appends(['gotoelement' => "msgs"])->render() !!}` to the last bit where the page links are rendered at the bottom. So now I'm passing a variable into the next page. I was now wondering if I could have a check in my view for this parameter that will jump to that element if it happens to be set. I'm not sure how to do this (javascript?) or if it's the right way to go about it. – Nicholas Kontos Aug 01 '15 at 16:11
  • If there is a way to always append `$gotoelement` to the view went I call it from my controller when I `return view('homepages.index')` to change the url from `/home' to `/home/#msgs` – Nicholas Kontos Aug 01 '15 at 16:19

1 Answers1

0

You might want to use fragment() method:

{!! $messages->fragment('msgs')->render() !!}

Here is the link to the documentation: Pagination - Laravel

amith.gotamey
  • 968
  • 8
  • 14
  • That's exactly what I was looking for. It was right in with the pagination documentation too... I must have missed it. Thank you – Nicholas Kontos Aug 18 '15 at 18:00