0
votes

I have a bit type column in database table. First I was having problem saving field which solved by this question Laravel 4.2 BIT datatype issue

But now when I retrieve data i a getting that bit type field as {}.

"active": {}

Please help me if anyone has solution.

Edit: Sorry, the problem is while creating object.

I have a "schedule" table in which I have "active" field which is BIT. When I create new Schedule using laravel eloquent, returned object has 'active' field as emptystring {}, No matter bit value is 0 or 1.

$schedule = Schedule::create($input);

returns

{
      "active": {},
      "cityId": 84,
      "eventdate": "2015-09-01T00:00:00+05:30",
      "updatedon": "2015-09-15 16:53:48",
      "createdon": "2015-09-15 16:53:48"
}
1
in that question it self suggested change bit to tinyint right? - RaMeSh
And show me your query also,we can easily understand your problem - RaMeSh
change to bit to tinyint is right but i can't change database definition. - sp11
ok k look at my answer and try. - RaMeSh
I have edited my question, please look at it. - sp11

1 Answers

0
votes

I have faced same problem, i have done like this.

Normally i have retrieve like this but failed to get the email data.In this case email datatype is BIT.

$query = "SELECT Username, email FROM users";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
print_r($row);

after that i have tried like this and it's working fine for me.

$query = "SELECT Username, CAST(email AS unsigned integer) AS emailid FROM users";