79251562

Date: 2024-12-04 14:32:55
Score: 0.5
Natty:
Report link

I would try the following:

First, let's examine the SQL side. Check your table indexes:

SHOW INDEX FROM hr_ship_order;

There should be an index on the order_id column.

Then make sure that your SQL statements are working correctly.

Use the EXPLAIN command to see if the given SELECT statement is utilizing the table indexes:

Put the order_id in the SELECT as an integer:

EXPLAIN SELECT * FROM `hr_ship_order` WHERE `order_id` = 319769;

Then, as a string:

EXPLAIN SELECT * FROM `hr_ship_order` WHERE `order_id` = "319769";

Check the possible_keys and key columns in the result for both cases. In the second case, you should be able to see the indexes used during the SELECT.

Now, let's move on to the PHP/Laravel side.

Let's see the SQL result of your query:

dd(ShipOrderModel::where('order_id', $orderId)->toSql());

You should see something like this:

"select * from `hr_ship_order` where `order_id` = ?"

If you need the $orderId as a string everywhere, it might be a good idea to set a cast in the ShipOrderModel.

If order_id is a regular column:

protected $casts = [
    'order_id' => 'string'
];

If order_id is the primary key of your table:

protected $keyType = 'string';

Finally, check if the $orderId is still a string in the WHERE clause of the SELECT statement. Let's dd your query and check:

dd(ShipOrderModel::where('order_id', $orderId)

You can verify this by checking the output of the command above. Find the wheres array:

wheres: array:1 [▼
  0 => array:5 [▼
    "type" => "Basic"
    "column" => "order_id"
    "operator" => "="
    "value" => "319769"
    "boolean" => "and"
  ]
]

If the "value" is still a string, then everything is fine.

Last question, which could have been the first. :) What PHP and Laravel versions are you using?

Reasons:
  • Whitelisted phrase (-1): try the following
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: andrashandler