Ezra Ezra - 3 months ago 16
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

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'));
Comments