0

I have inherited a Laravel 4.2 codebase which has an admin control panel.

Users with role 3 have access to further admin options. Everything is set up fine and working on the live build, however, locally Auth::user()->role is outputting as a string, when the build is geared to look for an integer.

I can't edit all the if / else permission statements to force an integer.

Is there something simple I should be looking for?

Cheers

Sam Holguin
  • 553
  • 2
  • 9
  • 24
  • What do you mean by string? Do you mean literally a string of the number 3 `'3'` or do you mean it outputs a string like `admin`? What does `Auth::user()->role`/`role()` method look like? – haakym Sep 26 '16 at 17:33
  • String of the number... '3'. Yet it works perfectly on the live build – Sam Holguin Sep 26 '16 at 17:33
  • I think that would reflect the data type of your table. Do you have that column set to integer? – user1669496 Sep 26 '16 at 17:37
  • Where are you looking at the return value of the role in the live app vs locally? Is it in a test or a webpage or something? Also, how is this an issue - can you not cast the type? Perhaps the database is set up differently? Is it stored in a varchar instead of a integer? – haakym Sep 26 '16 at 17:37
  • Database column is set to int. it's an issue because the build is full of permission statements looking for an int. I don't want to have to cast the type, plus it's working live. I'm testing the local build. – Sam Holguin Sep 26 '16 at 17:39
  • 1
    Unless you are using scalar type-hinting or using `===` to compare, there's a good chance this doesn't matter, PHP tends to not care about these things unless you tell it to. – user1669496 Sep 26 '16 at 17:40
  • The conditionals are using === throughout :( – Sam Holguin Sep 26 '16 at 17:41
  • 2
    Sounds like PDO is returning wrong things. Take a look here http://stackoverflow.com/questions/20079320/php-pdo-mysql-how-do-i-return-integer-and-numeric-columns-from-mysql-as-int – user1669496 Sep 26 '16 at 17:44
  • @user3158900 you my friend, are a genius! Leave it as an answer and I'll mark it correct :) – Sam Holguin Sep 26 '16 at 18:01

1 Answers1

1

Be sure you are using the mysqlnd driver for MySQL.

See PHP + PDO + MySQL: how do I return integer and numeric columns from MySQL as integers and numerics in PHP? for more details.

Community
  • 1
  • 1
user1669496
  • 32,176
  • 9
  • 73
  • 65