bottelet's avatar

Laravel 5.2 pagination

I've been trying to create a pagination, that list 10 task on each page, but on the the user page where tasks are assigned to the user, but i keep getting this error:

ErrorException in Builder.php line 2161:
Call to undefined method Illuminate\Database\Query\Builder::links()

I've tried the following:

Controller

    public function show($id)
    { 
        $user = User::with('tasksAssign')->whereId($id)->firstOrFail();
        $tasks = $user->tasksAssign()->paginate(10);
        return view('users.show', compact('user', 'tasks'));
    }

View:

    @foreach($tasks as $task)
        {{ $task->title }}

    @endforeach
    {!! $user->links() !!} //Both inside and outside the loop

And i've tried this aswell:

Controller

    $user = User::findOrFail($id);
        return view('users.show')->withUser($user);

My view:

              @foreach($user->tasksAssign() as $task)

                         <tr>
              <td>
              <a href="{{ route('tasks.show', $task->id)}}">
              {{ $task->title }}
              </a> </td>
              <td>{{date('d, F Y, H:i:s', strTotime($task->created_at))}} </td>
              <td>{{date('d, F Y', strTotime($task->deadline))}}({{ $task->days_until_deadline }})</td>
              </tr>
              @endforeach
0 likes
2 replies
thomaskim's avatar
Level 41

Well, you are paginating the tasks, not the user, so it should be:

{!! $tasks->links() !!}
2 likes
bottelet's avatar

Ah yes, dont know why i tried to do that on the user, stupid me :) Thank you so much @thomaskim !

Please or to participate in this conversation.