0
public function all_contact(){
  $contacts = contacts::with('user')->orderBy('id','desc')->get()->paginate(5);
  return response()->json([
    'contacts'=>$contacts
  ],200);
}

It gives error:

Method Illuminate\\Database\\Eloquent\\Collection::paginate does not exist.
1
  • 3
    Remove the ->get() Commented Aug 23, 2019 at 16:27

1 Answer 1

2

You are using ->get()->paginate(5);.When using ->get() method you get Collection instance. Change your code to

public function all_contact(){
    $contacts = contacts::with('user')->orderBy('id','desc')->paginate(5);
    return response()->json([
        'contacts'=>$contacts
    ],200);
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.