Ezra Ezra - 1 year ago 105
PHP Question

laravel 5.2 only paginate data with current user id

I want to paginate the data according to current logged in user.

this is my controller :

public function index()
$dosen = Dosen::paginate(5);
return view('dosen.index', compact('dosen'));

Answer Source

I'm assuming you've a user_id column in your Dosen model table. So you can say

$dosen = Dosen::where('user_id', auth()->user()->id)->paginate(5);

return view('dosen.index', compact('dosen'));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download