Column with space and hypen delimited string #50920
Unanswered
jasonhoule
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Have you tried replacing the space with %20 ?
And in the fillable array you use/define them as _ separated. Also when they go to db for saving you must replace _ with space again. |
Beta Was this translation helpful? Give feedback.
1 reply
-
I cannot reproduce it... Are you using Microsoft's official PHP drivers? Tested with the latest official driver (as of this writing: 5.12.0) from: https://github.com/microsoft/msphpsql And SQL Server 2019 running on docker, as described from Microsoft Learn:
<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Artisan;
class Sample extends Model
{
}
Artisan::command('test', function () {
$sql = <<<'SQL'
DROP TABLE [sample].[dbo].[samples];
CREATE TABLE [sample].[dbo].[samples] (
[Lawson Coding] VARCHAR(100) NULL,
[Lawson Company] VARCHAR(100) NULL,
[Lawson CostCenter] VARCHAR(100) NULL,
[Lawson Account] VARCHAR(100) NULL
);
INSERT INTO [sample].[dbo].[samples] (
[Lawson Coding],
[Lawson Company],
[Lawson CostCenter],
[Lawson Account]
)
VALUES ('101-10001-412014', '101', '10001', '412014');
SQL;
Sample::query()->getConnection()->unprepared($sql);
$coding = Sample::query()->first();
\dump($coding->{'Lawson Coding'});
\dump($coding->getAttribute('Lawson Coding'));
}); Output: $ php artisan test
"101-10001-412014" // routes/console.php:34
"101-10001-412014" // routes/console.php:35
$ php -v
PHP 8.2.18 (cli) (built: Apr 12 2024 12:00:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.18, Copyright (c) Zend Technologies
with Zend OPcache v8.2.18, Copyright (c), by Zend Technologies
$ php artisan --version
Laravel Framework 10.48.7
$ php artisan db
1> select @@version;
2> go
----------------------------------------------------------------------
Microsoft SQL Server 2019 (RTM-CU26) (KB5035123) - 15.0.4365.2 (X64)
Mar 29 2024 23:02:47
Copyright (C) 2019 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 20.04.6 LTS) <X64>
(1 rows affected)
1> exit |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
10.10
PHP Version
8.1.0
Database Driver & Version
MS SQL Server 2019
Description
I am having some trouble figuring out what is going on here. This is a legacy MS SQL database. The column names have spaces. When trying to get the value of the "Lawson Coding" column it is only returning the first portion of a hyphen delimited string for the eloquent model. I can get the attributes array and get the correct value but trying to get it from the eloquent object only returns the first portion (101) of the string.
}
Steps To Reproduce
I am not entirely sure. A database with spaces in the column names and a hyphen delimited value. SQL Server?
Beta Was this translation helpful? Give feedback.
All reactions