1

My code like this :

$test = $this->vendorRepository->getVendor($request->get('q'));

If I dd($test), the result is collection like this :

enter image description here

I want to convert it to array

I try like this :

dd($test->toArray());

The result like this :

enter image description here

value of id changed to 0

Why did it happen? How can I solve this problem?

2
  • i think your first image is not a collection. Can you add the output from starting ? you can access your data like this ‘$test->name’ Commented Jul 28, 2018 at 7:38
  • @rkj I had update it Commented Jul 28, 2018 at 7:40

1 Answer 1

3

This might be because your ID field is a string but laravel is expecting it to be an auto-incrementing integer.

Try adding this to the top of your model:

public $incrementing = false;
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.