php - Eloquent query returning null when using a variable - Stack Overflow

I am having a issue where when i write out a eloquent query using a variable it is returning NULL but i

I am having a issue where when i write out a eloquent query using a variable it is returning NULL but if i write out that variable value in text it returns data.

This is my code

$code = 'Test123';

LiveProducts::where('code', $code)->first();

When i dump that query out i get NULL, but if i type it out like this:

LiveProducts::where('code', 'Test123')->first();

Then it will return data from the database.

I have dumped out the variable and it is defiantly a string.

I am having a issue where when i write out a eloquent query using a variable it is returning NULL but if i write out that variable value in text it returns data.

This is my code

$code = 'Test123';

LiveProducts::where('code', $code)->first();

When i dump that query out i get NULL, but if i type it out like this:

LiveProducts::where('code', 'Test123')->first();

Then it will return data from the database.

I have dumped out the variable and it is defiantly a string.

Share Improve this question edited Mar 26 at 18:46 Tim Lewis 29.3k14 gold badges80 silver badges107 bronze badges Recognized by PHP Collective asked Mar 26 at 9:07 Adam AllenAdam Allen 2041 gold badge3 silver badges12 bronze badges 9
  • 2 Please keep in mind that Laravel 5 is EOL since nearly five years! – Nico Haase Commented Mar 26 at 9:22
  • 2 For the reason Nico Haase specified, I don't have a Laravel 5 app available to test this, but in Laravel 10 and 11 running the query $uuid = '...', then Model::where('uuid', $uuid)->first() and Model::where('uuid', '...')->first() both return the same single result (I don't have a code column, but same idea)... I can't recreate this, and I have no idea why this would be an error in your code; that's the syntax I've been using for over a decade

    发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744156353a4560880.html

相关推荐

  • php - Eloquent query returning null when using a variable - Stack Overflow

    I am having a issue where when i write out a eloquent query using a variable it is returning NULL but i

    9天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信