Level 55
Can you dd($user) before you call paginate on it, to make sure you actually have a User.
Try this:
$user = User::with('urls')->whereId($id)->paginate(10);
I'm trying to create simple pagination but I get error:
Undefined property: Illuminate\Pagination\Paginator::$name (View: /home/lipa/php/awsomelink/app/views/user/index.blade.php)
My controller:
$user = User::with('urls')->find($id)->paginate(10);
My View:
@foreach($user->urls as $link)
<li>
{{ HTML::link($link->shortened, "awsomelink.com/$link->shortened") }}
{{ Form::open(array('route' => array('url.delete', $link->id), 'method' => 'delete', 'class' => 'destroy')) }}
{{ Form::submit('Delete') }}
{{ Form::close() }}
<li>
@endforeach
<p>{{ $user->links(); }}</p>
From what I understand they want to paginate the User's URLS.
$user = User::with('urls')->whereId($id)->firstOrFail(); // or just $user = User::findOrFail($id);
$urls = $user->urls()->paginate(10);
// then pass both variables to the view
return view('user.index', compact('user', 'urls'));
// and loop through the products directly
@foreach ($urls as $url) ...
See this post here https://laracasts.com/discuss/channels/general-discussion/eager-loading-with-pagination/replies/31223
Please or to participate in this conversation.