Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Eloquent Serialization

Tags:

I have a table where the Primary Key looks like this: 123456-789 in column id. When I request all the entries from my table using $allArray = $this->all()->toArray() I have an issue. All the data arrives as expected but the id now looks like this: 123456789. The id column is set as varchar(24) utf8_general_ci in the database.

When I print_r() my result from $all = $this->all() (without ->toArray()) I can see that the id was fetched currently 123456-789. Then I try to get the id again like echo $all[1]->id it is 123456789.

Any help would be appreciated. Thank you :)

like image 291
Dvir Levy Avatar asked Feb 24 '18 19:02

Dvir Levy


1 Answers

You should let your model know that primary key is not auto incrementing value else it will try to convert the primary key into an integer.

Simply add this to your model.

public $incrementing = false;
like image 98
Gowthamraj Vungarala Avatar answered Sep 19 '22 12:09

Gowthamraj Vungarala